Skip to content

Commit

Permalink
Refactor de modulos de tests
Browse files Browse the repository at this point in the history
refs:#87
  • Loading branch information
leandro-gomez committed Dec 20, 2017
1 parent 13d2de6 commit 18ac662
Show file tree
Hide file tree
Showing 10 changed files with 135 additions and 127 deletions.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals

from .utils import jsonschema_str
from tests.support.utils import jsonschema_str


def catalog_error_response(options=None):
def catalog_error(options=None):
default_options = {
'title': "Datos Argentina",
'message': None,
Expand Down Expand Up @@ -56,27 +56,27 @@ def catalog_error_response(options=None):


def missing_catalog_dataset():
return catalog_error_response({
return catalog_error({
'message': "%s is a required property" % jsonschema_str('dataset'),
'dataset': None,
})


def missing_catalog_title():
return catalog_error_response({
return catalog_error({
'message': "%s is a required property" % jsonschema_str('title'),
'title': None,
})


def missing_catalog_description():
return catalog_error_response({
return catalog_error({
'message': "%s is a required property" % jsonschema_str('description'),
})


def invalid_catalog_publisher_type():
return catalog_error_response({
return catalog_error({
'instance': [
"Ministerio de Modernización",
"datos@modernizacion.gob.ar"
Expand All @@ -95,7 +95,7 @@ def invalid_catalog_publisher_type():


def invalid_publisher_mbox_format():
return catalog_error_response({
return catalog_error({
"error_code": 2,
"message": "%s is not a %s" % (
jsonschema_str('datosATmodernizacion.gob.ar'), jsonschema_str('email')),
Expand All @@ -110,7 +110,7 @@ def invalid_publisher_mbox_format():


def null_catalog_publisher():
return catalog_error_response({
return catalog_error({
"error_code": 2,
"message": "None is not of type %s" % jsonschema_str('object'),
"path": ['publisher'],
Expand All @@ -120,7 +120,7 @@ def null_catalog_publisher():


def empty_mandatory_string():
return catalog_error_response({
return catalog_error({
"error_code": 2,
"message": "%s is too short" % jsonschema_str(''),
"path": ['description'],
Expand All @@ -131,7 +131,7 @@ def empty_mandatory_string():


def malformed_date():
return catalog_error_response({
return catalog_error({
"instance": "2016/04/14",
"validator": "anyOf",
"path": [
Expand Down Expand Up @@ -160,7 +160,7 @@ def malformed_date():


def malformed_datetime():
return catalog_error_response({
return catalog_error({
"instance": "2016-04-1419:48:05.433640-03:00",
"validator": "anyOf",
"path": [
Expand Down Expand Up @@ -190,7 +190,7 @@ def malformed_datetime():


def malformed_datetime2():
return catalog_error_response({
return catalog_error({
"instance": "2016-04-54T19:48:05.433640-03:00",
"validator": "anyOf",
"path": [
Expand Down Expand Up @@ -220,7 +220,7 @@ def malformed_datetime2():


def malformed_email():
return catalog_error_response({
return catalog_error({
"instance": "datosATmodernizacion.gob.ar",
"validator": "format",
"path": [
Expand All @@ -235,7 +235,7 @@ def malformed_email():


def malformed_uri():
return catalog_error_response({
return catalog_error({
"instance": "datos.gob.ar/superThemeTaxonomy.json",
"validator": "format",
"path": [
Expand All @@ -249,7 +249,7 @@ def malformed_uri():


def invalid_theme_taxonomy():
return catalog_error_response({
return catalog_error({
"instance": None,
"validator": "repeatedValue",
"path": [
Expand All @@ -264,7 +264,7 @@ def invalid_theme_taxonomy():


def missing_dataset():
return catalog_error_response({
return catalog_error({
"instance": None,
"validator": "required",
"path": [],
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
# -*- coding: utf-8 -*-


from __future__ import unicode_literals
from __future__ import unicode_literals, absolute_import

from tests.factories.catalog_errors import missing_catalog_title, missing_catalog_description, \
from .catalog_errors import missing_catalog_title, \
missing_catalog_description, \
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, invalid_theme_taxonomy, missing_dataset
from tests.factories.dataset_errors import missing_dataset_title, missing_dataset_description, \
from .dataset_errors import missing_dataset_title, \
missing_dataset_description, \
malformed_accrualperiodicity, malformed_temporal, malformed_temporal2, too_long_field_title
from tests.factories.other_errors import multiple_missing_descriptions, invalid_multiple_fields_type
from .utils import jsonschema_str
from .distribution_errors import missing_distribution_title
from .other_errors import multiple_missing_descriptions, \
invalid_multiple_fields_type

FULL_DATA_RESPONSE = {
"status": "OK",
Expand Down Expand Up @@ -39,7 +42,7 @@
}
}

TEST_FILE_RESPONSES = {
TEST_FROM_RESULT_FILE = {
# Tests de CAMPOS REQUERIDOS
# Tests de inputs válidos
'full_data': FULL_DATA_RESPONSE,
Expand All @@ -60,53 +63,7 @@

}


def distribution_error():
return {
"status": "ERROR",
"error": {
"catalog": {
"status": "OK",
"errors": [],
"title": "Datos Argentina"
},
"dataset": [
{
"status": "ERROR",
"identifier": "99db6631-d1c9-470b-a73e-c62daa32c420",
"list_index": 0,
"errors": [
{
"instance": None,
"validator": "required",
"path": [
"dataset",
0,
"distribution",
0
],
"message": "%s is a required property" % jsonschema_str('title'),
"error_code": 1,
"validator_value": [
"accessURL",
"downloadURL",
"title",
"issued"
]
}
],
"title": "Sistema de contrataciones electrónicas"
}
]
}
}


def missing_distribution_title():
return distribution_error()


DATAJSON_RESULTS = {
TEST_FROM_GENERATED_RESULT = {

'multiple_missing_descriptions': multiple_missing_descriptions(),
'invalid_multiple_fields_type': invalid_multiple_fields_type(),
Expand Down Expand Up @@ -137,4 +94,6 @@ def missing_distribution_title():
'invalid_publisher_mbox_format': invalid_publisher_mbox_format(),
}

TEST_FILE_RESPONSES.update(DATAJSON_RESULTS)
TEST_FILE_RESPONSES = {}
TEST_FILE_RESPONSES.update(TEST_FROM_RESULT_FILE)
TEST_FILE_RESPONSES.update(TEST_FROM_GENERATED_RESULT)
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@

from __future__ import unicode_literals

from tests.factories.utils import jsonschema_str
from tests.support.utils import jsonschema_str


def gen_dataset_error(options=None):
def dataset_error(options=None):
default_options = {
"dataset_title": "Sistema de contrataciones electrónicas",
"instance": "RP1Y",
"validator": "anyOf",
"path": [
Expand Down Expand Up @@ -58,71 +59,67 @@ def gen_dataset_error(options=None):
"validator_value": options['validator_value'],
}
],
"title": "Sistema de contrataciones electrónicas"
}
]
}
}


def dataset_error(string, dataset_title=None):
return {
"status": "ERROR",
"error": {
"catalog": {
"status": "OK",
"errors": [],
"title": "Datos Argentina"
},
"dataset": [
{
"status": "ERROR",
"identifier": "99db6631-d1c9-470b-a73e-c62daa32c420",
"list_index": 0,
"errors": [
{
"instance": None,
"validator": "required",
"path": [
"dataset",
0
],
"message": "%s is a required property" % jsonschema_str(string),
"error_code": 1,
"validator_value": [
"title",
"description",
"publisher",
"superTheme",
"distribution",
"accrualPeriodicity",
"issued"
]
}
],
"title": dataset_title
"title": options['dataset_title']
}
]
}
}


def missing_dataset_title():
return dataset_error('title')
return dataset_error({
"instance": None,
"validator": "required",
"path": [
"dataset",
0
],
"message": "%s is a required property" % jsonschema_str('title'),
"error_code": 1,
"validator_value": [
"title",
"description",
"publisher",
"superTheme",
"distribution",
"accrualPeriodicity",
"issued"
],
"dataset_title": None,
})


def missing_dataset_description():
return dataset_error('description', dataset_title='Sistema de contrataciones electrónicas')
return dataset_error({
"instance": None,
"validator": "required",
"path": [
"dataset",
0
],
"message": "%s is a required property" % jsonschema_str('description'),
"error_code": 1,
"validator_value": [
"title",
"description",
"publisher",
"superTheme",
"distribution",
"accrualPeriodicity",
"issued"
],
"dataset_title": 'Sistema de contrataciones electrónicas',
})


def malformed_accrualperiodicity():
return gen_dataset_error({
return dataset_error({
'message': "%s is not valid under any of the given schemas" % jsonschema_str('RP1Y'),
})


def malformed_temporal():
return gen_dataset_error({
return dataset_error({
"instance": "2015-01-1/2015-12-31",
"validator": "anyOf",
"path": [
Expand Down Expand Up @@ -150,7 +147,7 @@ def malformed_temporal():


def malformed_temporal2():
return gen_dataset_error({
return dataset_error({
"instance": "2015-01-10/31-12-2015",
"validator": "anyOf",
"path": [
Expand Down Expand Up @@ -178,7 +175,7 @@ def malformed_temporal2():


def too_long_field_title():
return gen_dataset_error({
return dataset_error({
"instance": "organismo_unidad_operativa_contrataciones_desc_organismo_unidad_operativa_contrataciones_desc",
"validator": "anyOf",
"path": [
Expand All @@ -190,7 +187,8 @@ def too_long_field_title():
3,
"title"
],
"message": "%s is not valid under any of the given schemas" % jsonschema_str('organismo_unidad_operativa_contrataciones_desc_organismo_unidad_operativa_contrataciones_desc'),
"message": "%s is not valid under any of the given schemas" % jsonschema_str(
'organismo_unidad_operativa_contrataciones_desc_organismo_unidad_operativa_contrataciones_desc'),
"error_code": 2,
"validator_value": [
{
Expand Down

0 comments on commit 18ac662

Please sign in to comment.