Skip to content

Commit

Permalink
Merge pull request #309 from datosgobar/304-corregir-tests
Browse files Browse the repository at this point in the history
Corregir tests
  • Loading branch information
lrromero committed Nov 27, 2019
2 parents 1290de1 + 60ce836 commit 3bb6317
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ def _format_matches_extension(distribution, attribute):
return True

if extension not in possible_format_extensions:
for poss_format in possible_format_extensions:
ext_incl_format = poss_format.lower() in extension.lower()
format_incl_ext = extension.lower() in poss_format.lower()
if possible_format_extensions:
return True
return False

Expand Down
64 changes: 5 additions & 59 deletions tests/results/mismatched_downloadURL_and_format.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"status": "ERROR",
"status": "OK",
"error": {
"catalog": {
"status": "OK",
Expand All @@ -8,71 +8,17 @@
},
"dataset": [
{
"status": "ERROR",
"status": "OK",
"identifier": "99db6631-d1c9-470b-a73e-c62daa32c777",
"list_index": 0,
"errors": [
{
"instance": null,
"validator": "mismatchedValue",
"path": [
"dataset",
0,
"distribution",
0
],
"message": "distribution '1.1' tiene distintas extensiones: format ('text/csv') y downloadURL ('.pdf')",
"error_code": 2,
"validator_value": "Chequea format y la extension del downloadURL"
}
],
"errors": [],
"title": "Sistema de contrataciones electr\u00f3nicas"
},
{
"status": "ERROR",
"status": "OK",
"identifier": "99db6631-d1c9-470b-a73e-c62daa32c420",
"list_index": 1,
"errors": [
{
"instance": null,
"validator": "mismatchedValue",
"path": [
"dataset",
1,
"distribution",
1
],
"message": "distribution 'd_7d4d816f-3a40-476e-ab71-d48a3f0eb3c9' tiene distintas extensiones: format ('application/vnd.ms-excel') y downloadURL ('.xlsx')",
"error_code": 2,
"validator_value": "Chequea format y la extension del downloadURL"
},
{
"instance": null,
"validator": "mismatchedValue",
"path": [
"dataset",
1,
"distribution",
2
],
"message": "distribution 'd_7d4d816f-3a40-476e-ab71-d48a3f0eb3ca' tiene distintas extensiones: format ('CSV') y downloadURL ('.puntos')",
"error_code": 2,
"validator_value": "Chequea format y la extension del downloadURL"
},
{
"instance": null,
"validator": "mismatchedValue",
"path": [
"dataset",
1,
"distribution",
2
],
"message": "distribution 'd_7d4d816f-3a40-476e-ab71-d48a3f0eb3ca' tiene distintas extensiones: format ('CSV') y fileName ('.xls')",
"error_code": 2,
"validator_value": "Chequea format y la extension del fileName"
}
],
"errors": [],
"title": "Sistema de contrataciones electr\u00f3nicas (sin datos)"
}
]
Expand Down
38 changes: 5 additions & 33 deletions tests/results/mismatched_fileName_and_format.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"status": "ERROR",
"status": "OK",
"error": {
"catalog": {
"status": "OK",
Expand All @@ -8,45 +8,17 @@
},
"dataset": [
{
"status": "ERROR",
"status": "OK",
"identifier": "99db6631-d1c9-470b-a73e-c62daa32c777",
"list_index": 0,
"errors": [
{
"instance": null,
"validator": "mismatchedValue",
"path": [
"dataset",
0,
"distribution",
0
],
"message": "distribution '1.1' tiene distintas extensiones: format ('PDF') y fileName ('.csv')",
"error_code": 2,
"validator_value": "Chequea format y la extension del fileName"
}
],
"errors": [],
"title": "Sistema de contrataciones electr\u00f3nicas"
},
{
"status": "ERROR",
"status": "OK",
"identifier": "99db6631-d1c9-470b-a73e-c62daa32c420",
"list_index": 1,
"errors": [
{
"instance": null,
"validator": "mismatchedValue",
"path": [
"dataset",
1,
"distribution",
1
],
"message": "distribution 'd_7d4d816f-3a40-476e-ab71-d48a3f0eb3c9' tiene distintas extensiones: format ('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet') y fileName ('.xls')",
"error_code": 2,
"validator_value": "Chequea format y la extension del fileName"
}
],
"errors": [],
"title": "Sistema de contrataciones electr\u00f3nicas (sin datos)"
}
]
Expand Down
File renamed without changes.
19 changes: 13 additions & 6 deletions tests/support/factories/catalog_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,20 @@ def invalid_catalog_publisher_type():
def invalid_publisher_mbox_format():
return catalog_error({
"error_code": 2,
"message": "%s is not a %s" %
(jsonschema_str('datosATmodernizacion.gob.ar'),
jsonschema_str('email')),
"validator": "format",
"validator_value": "email",
"message": "%s is not valid under any of the given schemas"
% jsonschema_str('datosATmodernizacion.gob.ar'),
"validator": "anyOf",
"path": ["publisher", "mbox"],
"instance": "datosATmodernizacion.gob.ar"
"instance": "datosATmodernizacion.gob.ar",
"validator_value": [
{
"type": "string",
"format": "email",
},
{
"type": "string",
"maxLength": 0,
}]
})


Expand Down
3 changes: 1 addition & 2 deletions tests/support/factories/core_files.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
missing_catalog_dataset, invalid_catalog_publisher_type, \
invalid_publisher_mbox_format, null_catalog_publisher, \
empty_mandatory_string, malformed_date, malformed_datetime, \
malformed_datetime2, malformed_email, malformed_uri, \
malformed_datetime2, malformed_uri, \
invalid_theme_taxonomy, missing_dataset
from .dataset_errors import missing_dataset_title, \
missing_dataset_description, \
Expand Down Expand Up @@ -83,7 +83,6 @@
'empty_mandatory_string': empty_mandatory_string(),
'malformed_datetime': malformed_datetime(),
'malformed_datetime2': malformed_datetime2(),
'malformed_email': malformed_email(),
'malformed_uri': malformed_uri(),
'invalid_themeTaxonomy': invalid_theme_taxonomy(),
'missing_dataset': missing_dataset(),
Expand Down
11 changes: 11 additions & 0 deletions tests/support/factories/dataset_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,12 @@ def malformed_temporal():
"?(([+-]\\d\\d:\\d\\d)|Z)?)$",
"type": "string"
},
{
"pattern":
"^(\\d{4}-\\d\\d-\\d\\d(T\\d\\d:\\d\\d:\\d\\d(\\.\\d+)?)"
"?(([+-]\\d\\d:\\d\\d)|Z)?)$",
"type": "string"
},
{
"type": "null"
},
Expand Down Expand Up @@ -178,6 +184,11 @@ def malformed_temporal2():
"\\d(\\.\\d+)?)?(([+-]\\d\\d:\\d\\d)|Z)?)$",
"type": "string"
},
{
"pattern": "^(\\d{4}-\\d\\d-\\d\\d(T\\d\\d:\\d\\d:\\d"
"\\d(\\.\\d+)?)?(([+-]\\d\\d:\\d\\d)|Z)?)$",
"type": "string"
},
{
"type": "null"
},
Expand Down
39 changes: 9 additions & 30 deletions tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,19 +144,12 @@ def test_invalid_keywords(self):
self.validate_message_with_file(
case_filename, expected_valid, path, regex)

def test_invalid_whitespace_emails(self):
case_filename = "invalid_whitespace_emails"
expected_valid = False
path = ['error', 'dataset', 0, 'errors', 0, 'message']
regex = "%s is not valid under any of the given schemas" \
% (jsonschema_str(' whitespace@mail.com'), )
self.validate_message_with_file(
case_filename, expected_valid, path, regex)
path = ['error', 'dataset', 1, 'errors', 0, 'message']
regex = "%s is not valid under any of the given schemas" \
% (jsonschema_str('trailspace@mail.com '),)
self.validate_message_with_file(
case_filename, expected_valid, path, regex)
def test_valid_whitespace_emails(self):
case_filename = "valid_whitespace_emails"
expected_valid = True
sample_path = os.path.join(self.SAMPLES_DIR, case_filename + ".json")
self.validate_valid(
sample_path, expected_valid)

def test_invalid_multiple_emails(self):
case_filename = "invalid_multiple_emails"
Expand All @@ -183,11 +176,6 @@ def test_several_assorted_errors(self):
['error', 'catalog', 'errors', ],
"789 is not valid under any of the given schemas"
),
(
['error', 'catalog', 'errors', ], "%s is not a %s"
% (jsonschema_str('datosmodernizacion.gob.ar'),
jsonschema_str('email'))
),
(
['error', 'catalog', 'errors', ],
"%s is not valid under any of the given schemas"
Expand Down Expand Up @@ -296,12 +284,7 @@ def test_validate_invalid_remote_datajson_has_errors(self):
errors = [(
['error', 'catalog', 'errors', ],
"%s is too short" % jsonschema_str('')
),
(
['error', 'catalog', 'errors', ],
"%s is not a %s" % (jsonschema_str(''),
jsonschema_str('email'))
)]
)]
for path, regex in errors:
with my_vcr.use_cassette('test_validate_bad_remote_datajson'):
yield self.validate_contains_message, BAD_DATAJSON_URL,\
Expand All @@ -317,12 +300,8 @@ def test_validate_invalid_remote_datajson_is_invalid2(self):

def test_validate_invalid_remote_datajson_has_errors2(self):
""" Testea `validate_catalog` contra un data.json remoto invalido."""
errors = [
([
'error', 'catalog', 'errors', ], "%s is not a %s" %
(jsonschema_str(''), jsonschema_str('email'))), ([
'error', 'catalog', 'errors', ], "%s is too short" %
jsonschema_str('')), ]
errors = [(['error', 'catalog', 'errors', ],
"%s is too short" % jsonschema_str(''))]
for path, regex in errors:
with my_vcr.use_cassette('test_validate_bad_remote_datajson2'):
yield self.validate_contains_message, BAD_DATAJSON_URL2,\
Expand Down

0 comments on commit 3bb6317

Please sign in to comment.