diff --git a/.codacy.yaml b/.codacy.yaml new file mode 100644 index 00000000..4758da52 --- /dev/null +++ b/.codacy.yaml @@ -0,0 +1,5 @@ +--- +engines: + pylintpython3: + enabled: true + python_version: 3 diff --git a/.pylintrc b/.pylintrc new file mode 100644 index 00000000..3539e9a8 --- /dev/null +++ b/.pylintrc @@ -0,0 +1,4 @@ +[FORMAT] + +# Maximum number of characters on a single line. +max-line-length=110 diff --git a/CHANGELOG b/CHANGELOG index 79a942ab..9b572e0d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -4,9 +4,10 @@ Changelog 2.0.5 ----- -Supported GEO-Link API versions: v1.0.0, v1.1.0, v1.1.1, v1.2.0, v1.2.1, v1.2.2 (default), v1.2.3 +Supported GEO-Link API versions: v1.0.0, v1.1.0, v1.1.1, v1.2.0, v1.2.1, v1.2.2, v1.2.3, v1.2.4 (default) - Fix html rendering of documents with abrogation date +- Dependency updates 2.0.4 ----- diff --git a/geolink_formatter/parser.py b/geolink_formatter/parser.py index a1b93e65..d11b763e 100644 --- a/geolink_formatter/parser.py +++ b/geolink_formatter/parser.py @@ -31,13 +31,16 @@ class SCHEMA(object): V1_2_3 = '1.2.3' """str: geoLink schema version 1.2.3""" + V1_2_4 = '1.2.4' + """str: geoLink schema version 1.2.3""" + class XML(object): _date_format = '%Y-%m-%d' """str: Format of date values in XML.""" - def __init__(self, host_url=None, version='1.2.2', dtd_validation=False, xsd_validation=True): + def __init__(self, host_url=None, version='1.2.4', dtd_validation=False, xsd_validation=True): """Create a new XML parser instance containing the geoLink XSD for validation. Args: diff --git a/geolink_formatter/schema/v1.2.4.xsd b/geolink_formatter/schema/v1.2.4.xsd new file mode 100644 index 00000000..2849c956 --- /dev/null +++ b/geolink_formatter/schema/v1.2.4.xsd @@ -0,0 +1,166 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/resources/geolink_v1.2.4.xml b/tests/resources/geolink_v1.2.4.xml new file mode 100644 index 00000000..084666a3 --- /dev/null +++ b/tests/resources/geolink_v1.2.4.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/resources/geolink_v1.2.4_error_status.xml b/tests/resources/geolink_v1.2.4_error_status.xml new file mode 100644 index 00000000..556ad7ee --- /dev/null +++ b/tests/resources/geolink_v1.2.4_error_status.xml @@ -0,0 +1,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/tests/resources/prepublink_v1.2.4.xml b/tests/resources/prepublink_v1.2.4.xml new file mode 100644 index 00000000..7c87709b --- /dev/null +++ b/tests/resources/prepublink_v1.2.4.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/resources/prepublink_v1.2.4_error_enactment_date.xml b/tests/resources/prepublink_v1.2.4_error_enactment_date.xml new file mode 100644 index 00000000..a28303b2 --- /dev/null +++ b/tests/resources/prepublink_v1.2.4_error_enactment_date.xml @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/test_parser.py b/tests/test_parser.py index e5203fbe..7431b629 100644 --- a/tests/test_parser.py +++ b/tests/test_parser.py @@ -263,7 +263,7 @@ def test_schema_version_1_2_3(): with requests_mock.mock() as m: with open('tests/resources/geolink_v1.2.3.xml', 'rb') as f: m.get('http://oereblex.test.com/api/geolinks/1500.xml', content=f.read()) - documents = XML(version=SCHEMA.V1_2_2).from_url('http://oereblex.test.com/api/geolinks/1500.xml') + documents = XML(version=SCHEMA.V1_2_3).from_url('http://oereblex.test.com/api/geolinks/1500.xml') assert len(documents) == 5 assert documents[0].index is None assert documents[-3].index == 1 @@ -275,7 +275,7 @@ def test_schema_version_1_2_3_prepublink(): with requests_mock.mock() as m: with open('tests/resources/prepublink_v1.2.3.xml', 'rb') as f: m.get('http://oereblex.test.com/api/geolinks/1500.xml', content=f.read()) - documents = XML(version=SCHEMA.V1_2_2).from_url('http://oereblex.test.com/api/geolinks/1500.xml') + documents = XML(version=SCHEMA.V1_2_3).from_url('http://oereblex.test.com/api/geolinks/1500.xml') assert len(documents) == 6 assert documents[0].index is None assert documents[-3].index == 1 @@ -288,7 +288,7 @@ def test_schema_version_1_2_3_faulty_prepublink(): with requests_mock.mock() as m: with open('tests/resources/prepublink_v1.2.3_error_enactment_date.xml', 'rb') as f: m.get('http://oereblex.test.com/api/geolinks/1500.xml', content=f.read()) - XML(version=SCHEMA.V1_2_2).from_url('http://oereblex.test.com/api/geolinks/1500.xml') + XML(version=SCHEMA.V1_2_3).from_url('http://oereblex.test.com/api/geolinks/1500.xml') def test_schema_version_1_2_3_faulty_geolink(): @@ -296,7 +296,47 @@ def test_schema_version_1_2_3_faulty_geolink(): with requests_mock.mock() as m: with open('tests/resources/geolink_v1.2.3_error_status.xml', 'rb') as f: m.get('http://oereblex.test.com/api/geolinks/1500.xml', content=f.read()) - XML(version=SCHEMA.V1_2_2).from_url('http://oereblex.test.com/api/geolinks/1500.xml') + XML(version=SCHEMA.V1_2_3).from_url('http://oereblex.test.com/api/geolinks/1500.xml') + + +def test_schema_version_1_2_4(): + with requests_mock.mock() as m: + with open('tests/resources/geolink_v1.2.4.xml', 'rb') as f: + m.get('http://oereblex.test.com/api/geolinks/1500.xml', content=f.read()) + documents = XML(version=SCHEMA.V1_2_4).from_url('http://oereblex.test.com/api/geolinks/1500.xml') + assert len(documents) == 5 + assert documents[0].index is None + assert documents[-3].index == 1 + assert documents[-2].index == 2 + assert documents[-1].index == 3 + + +def test_schema_version_1_2_4_prepublink(): + with requests_mock.mock() as m: + with open('tests/resources/prepublink_v1.2.4.xml', 'rb') as f: + m.get('http://oereblex.test.com/api/geolinks/1500.xml', content=f.read()) + documents = XML(version=SCHEMA.V1_2_4).from_url('http://oereblex.test.com/api/geolinks/1500.xml') + assert len(documents) == 6 + assert documents[0].index is None + assert documents[-3].index == 1 + assert documents[-2].index == 2 + assert documents[-1].index == 3 + + +def test_schema_version_1_2_4_faulty_prepublink(): + with pytest.raises(xmlschema.XMLSchemaValidationError): + with requests_mock.mock() as m: + with open('tests/resources/prepublink_v1.2.4_error_enactment_date.xml', 'rb') as f: + m.get('http://oereblex.test.com/api/geolinks/1500.xml', content=f.read()) + XML(version=SCHEMA.V1_2_4).from_url('http://oereblex.test.com/api/geolinks/1500.xml') + + +def test_schema_version_1_2_4_faulty_geolink(): + with pytest.raises(xmlschema.XMLSchemaValidationError): + with requests_mock.mock() as m: + with open('tests/resources/geolink_v1.2.4_error_status.xml', 'rb') as f: + m.get('http://oereblex.test.com/api/geolinks/1500.xml', content=f.read()) + XML(version=SCHEMA.V1_2_4).from_url('http://oereblex.test.com/api/geolinks/1500.xml') def test_default_version_with_locale():