|
37 | 37 | # Un datajson con valores correctos únicamente para las claves requeridas
|
38 | 38 | 'minimum_data': None,
|
39 | 39 | # Tests de inputs inválidos
|
40 |
| - 'missing_catalog_title': None, |
41 |
| - 'missing_catalog_description': None, |
42 |
| - 'missing_catalog_dataset': None, |
43 |
| - 'missing_dataset_title': None, |
44 |
| - 'missing_dataset_description': None, |
45 |
| - 'missing_distribution_title': None, |
| 40 | + # 'missing_catalog_title': None, |
| 41 | + # 'missing_catalog_description': None, |
| 42 | + # 'missing_catalog_dataset': None, |
| 43 | + # 'missing_dataset_title': None, |
| 44 | + # 'missing_dataset_description': None, |
| 45 | + # 'missing_distribution_title': None, |
46 | 46 | 'multiple_missing_descriptions': None,
|
47 | 47 |
|
48 | 48 | # Tests de TIPOS DE CAMPOS
|
|
85 | 85 | 'several_assorted_errors': None,
|
86 | 86 |
|
87 | 87 | }
|
| 88 | + |
| 89 | + |
| 90 | +def jsonschema_str(string): |
| 91 | + return repr(string) |
| 92 | + |
| 93 | + |
| 94 | +DEFAULT_OPTIONS = { |
| 95 | + 'title': "Datos Argentina", |
| 96 | + 'message': None, |
| 97 | + 'dataset': [ |
| 98 | + { |
| 99 | + "status": "OK", |
| 100 | + "identifier": "99db6631-d1c9-470b-a73e-c62daa32c420", |
| 101 | + "list_index": 0, |
| 102 | + "errors": [], |
| 103 | + "title": "Sistema de contrataciones electrónicas" |
| 104 | + } |
| 105 | + ] |
| 106 | +} |
| 107 | + |
| 108 | + |
| 109 | +def error_response(options=None): |
| 110 | + default_options = DEFAULT_OPTIONS.copy() |
| 111 | + if options is not None: |
| 112 | + default_options.update(options) |
| 113 | + options = default_options |
| 114 | + return { |
| 115 | + "status": "ERROR", |
| 116 | + "error": { |
| 117 | + "catalog": { |
| 118 | + "status": "ERROR", |
| 119 | + "errors": [ |
| 120 | + { |
| 121 | + "instance": None, |
| 122 | + "validator": "required", |
| 123 | + "path": [], |
| 124 | + "message": options['message'], |
| 125 | + "error_code": 1, |
| 126 | + "validator_value": [ |
| 127 | + "dataset", |
| 128 | + "title", |
| 129 | + "description", |
| 130 | + "publisher", |
| 131 | + "superThemeTaxonomy" |
| 132 | + ] |
| 133 | + } |
| 134 | + ], |
| 135 | + "title": options['title'], |
| 136 | + }, |
| 137 | + "dataset": options['dataset'], |
| 138 | + } |
| 139 | + } |
| 140 | + |
| 141 | + |
| 142 | +def missing_catalog_dataset(): |
| 143 | + return error_response({ |
| 144 | + 'message': "%s is a required property" % jsonschema_str('dataset'), |
| 145 | + 'dataset': None, |
| 146 | + }) |
| 147 | + |
| 148 | + |
| 149 | +def missing_catalog_title(): |
| 150 | + return error_response({ |
| 151 | + 'message': "%s is a required property" % jsonschema_str('title'), |
| 152 | + 'title': None, |
| 153 | + }) |
| 154 | + |
| 155 | + |
| 156 | +def missing_catalog_description(): |
| 157 | + return error_response({ |
| 158 | + 'message': "%s is a required property" % jsonschema_str('description'), |
| 159 | + }) |
| 160 | + |
| 161 | + |
| 162 | +def distribution_error(): |
| 163 | + return { |
| 164 | + "status": "ERROR", |
| 165 | + "error": { |
| 166 | + "catalog": { |
| 167 | + "status": "OK", |
| 168 | + "errors": [], |
| 169 | + "title": "Datos Argentina" |
| 170 | + }, |
| 171 | + "dataset": [ |
| 172 | + { |
| 173 | + "status": "ERROR", |
| 174 | + "identifier": "99db6631-d1c9-470b-a73e-c62daa32c420", |
| 175 | + "list_index": 0, |
| 176 | + "errors": [ |
| 177 | + { |
| 178 | + "instance": None, |
| 179 | + "validator": "required", |
| 180 | + "path": [ |
| 181 | + "dataset", |
| 182 | + 0, |
| 183 | + "distribution", |
| 184 | + 0 |
| 185 | + ], |
| 186 | + "message": "%s is a required property" % jsonschema_str('title'), |
| 187 | + "error_code": 1, |
| 188 | + "validator_value": [ |
| 189 | + "accessURL", |
| 190 | + "downloadURL", |
| 191 | + "title", |
| 192 | + "issued" |
| 193 | + ] |
| 194 | + } |
| 195 | + ], |
| 196 | + "title": "Sistema de contrataciones electrónicas" |
| 197 | + } |
| 198 | + ] |
| 199 | + } |
| 200 | + } |
| 201 | + |
| 202 | + |
| 203 | +def dataset_error(string, dataset_title=None): |
| 204 | + return { |
| 205 | + "status": "ERROR", |
| 206 | + "error": { |
| 207 | + "catalog": { |
| 208 | + "status": "OK", |
| 209 | + "errors": [], |
| 210 | + "title": "Datos Argentina" |
| 211 | + }, |
| 212 | + "dataset": [ |
| 213 | + { |
| 214 | + "status": "ERROR", |
| 215 | + "identifier": "99db6631-d1c9-470b-a73e-c62daa32c420", |
| 216 | + "list_index": 0, |
| 217 | + "errors": [ |
| 218 | + { |
| 219 | + "instance": None, |
| 220 | + "validator": "required", |
| 221 | + "path": [ |
| 222 | + "dataset", |
| 223 | + 0 |
| 224 | + ], |
| 225 | + "message": "%s is a required property" % jsonschema_str(string), |
| 226 | + "error_code": 1, |
| 227 | + "validator_value": [ |
| 228 | + "title", |
| 229 | + "description", |
| 230 | + "publisher", |
| 231 | + "superTheme", |
| 232 | + "distribution", |
| 233 | + "accrualPeriodicity", |
| 234 | + "issued" |
| 235 | + ] |
| 236 | + } |
| 237 | + ], |
| 238 | + "title": dataset_title |
| 239 | + } |
| 240 | + ] |
| 241 | + } |
| 242 | + } |
| 243 | + |
| 244 | + |
| 245 | +def missing_dataset_title(): |
| 246 | + return dataset_error('title') |
| 247 | + |
| 248 | + |
| 249 | +def missing_dataset_description(): |
| 250 | + return dataset_error('description', dataset_title='Sistema de contrataciones electrónicas') |
| 251 | + |
| 252 | + |
| 253 | +def missing_distribution_title(): |
| 254 | + return distribution_error() |
| 255 | + |
| 256 | + |
| 257 | +DATAJSON_RESULTS = { |
| 258 | + 'missing_catalog_title': missing_catalog_title(), |
| 259 | + 'missing_catalog_description': missing_catalog_description(), |
| 260 | + 'missing_catalog_dataset': missing_catalog_dataset(), |
| 261 | + |
| 262 | + 'missing_dataset_title': missing_dataset_title(), |
| 263 | + 'missing_dataset_description': missing_dataset_description(), |
| 264 | + |
| 265 | + 'missing_distribution_title': missing_distribution_title() |
| 266 | +} |
| 267 | + |
| 268 | +TEST_FILE_RESPONSES.update(DATAJSON_RESULTS) |
0 commit comments