@@ -58,6 +58,88 @@ def test_submit_when_url_changes(self, monkeypatch):
58
58
59
59
assert func .called
60
60
61
+ @pytest .mark .ckan_config ("ckanext.xloader.validation.requires_successful_report" , True )
62
+ def test_require_validation (self , monkeypatch ):
63
+ func = mock .Mock ()
64
+ monkeypatch .setitem (_actions , "xloader_submit" , func )
65
+
66
+ mock_resource_validation_show = mock .Mock ()
67
+ monkeypatch .setitem (_actions , "resource_validation_show" , mock_resource_validation_show )
68
+
69
+ dataset = factories .Dataset ()
70
+
71
+ resource = helpers .call_action (
72
+ "resource_create" ,
73
+ {},
74
+ package_id = dataset ["id" ],
75
+ url = "http://example.com/file.csv" ,
76
+ format = "CSV" ,
77
+ validation_status = 'failure' ,
78
+ )
79
+
80
+ assert not func .called # because of the validation_status not being `success`
81
+ func .called = None # reset
82
+
83
+ helpers .call_action (
84
+ "resource_update" ,
85
+ {},
86
+ id = resource ["id" ],
87
+ package_id = dataset ["id" ],
88
+ url = "http://example.com/file2.csv" ,
89
+ format = "CSV" ,
90
+ validation_status = 'success' ,
91
+ )
92
+
93
+ assert func .called # because of the validation_status is `success`
94
+
95
+ @pytest .mark .ckan_config ("ckanext.xloader.validation.requires_successful_report" , True )
96
+ @pytest .mark .ckan_config ("ckanext.xloader.validation.enforce_schema" , False )
97
+ def test_enforce_validation_schema (self , monkeypatch ):
98
+ func = mock .Mock ()
99
+ monkeypatch .setitem (_actions , "xloader_submit" , func )
100
+
101
+ mock_resource_validation_show = mock .Mock ()
102
+ monkeypatch .setitem (_actions , "resource_validation_show" , mock_resource_validation_show )
103
+
104
+ dataset = factories .Dataset ()
105
+
106
+ resource = helpers .call_action (
107
+ "resource_create" ,
108
+ {},
109
+ package_id = dataset ["id" ],
110
+ url = "http://example.com/file.csv" ,
111
+ schema = '' ,
112
+ validation_status = '' ,
113
+ )
114
+
115
+ assert func .called # because of the schema being empty
116
+ func .called = None # reset
117
+
118
+ helpers .call_action (
119
+ "resource_update" ,
120
+ {},
121
+ id = resource ["id" ],
122
+ package_id = dataset ["id" ],
123
+ url = "http://example.com/file2.csv" ,
124
+ schema = 'https://example.com/schema.json' ,
125
+ validation_status = 'failure' ,
126
+ )
127
+
128
+ assert not func .called # because of the validation_status not being `success` and there is a schema
129
+ func .called = None # reset
130
+
131
+ helpers .call_action (
132
+ "resource_update" ,
133
+ {},
134
+ package_id = dataset ["id" ],
135
+ id = resource ["id" ],
136
+ url = "http://example.com/file3.csv" ,
137
+ schema = 'https://example.com/schema.json' ,
138
+ validation_status = 'success' ,
139
+ )
140
+
141
+ assert func .called # because of the validation_status is `success` and there is a schema
142
+
61
143
def _pending_task (self , resource_id ):
62
144
return {
63
145
"entity_id" : resource_id ,
0 commit comments