diff --git a/.codacy.yaml b/.codacy.yaml
new file mode 100644
index 00000000..05db93fe
--- /dev/null
+++ b/.codacy.yaml
@@ -0,0 +1,11 @@
+engines:
+ pylintpython3:
+ enabled: true
+ python_version: 3
+ bandit:
+ enabled: true
+ exclude_paths:
+ - "tests/**"
+
+exclude_paths:
+ - 'tests/**'
diff --git a/.pylintrc b/.pylintrc
new file mode 100644
index 00000000..bacf18ac
--- /dev/null
+++ b/.pylintrc
@@ -0,0 +1,4 @@
+[FORMAT]
+
+# Maximum number of characters on a single line.
+max-line-length=110
\ No newline at end of file
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..24255af3 100644
--- a/tests/test_parser.py
+++ b/tests/test_parser.py
@@ -136,8 +136,8 @@ def test_xml_from_url_invalid():
def test_xml_from_url_error():
- with requests_mock.mock() as m:
- m.get('http://oereblex.test.com/api/geolinks/1501.xml', text='error', status_code=500)
+ with requests_mock.mock() as mock_m:
+ mock_m.get('http://oereblex.test.com/api/geolinks/1501.xml', text='error', status_code=500)
with pytest.raises(RequestException):
XML().from_url('http://oereblex.test.com/api/geolinks/1501.xml')
@@ -158,18 +158,18 @@ def test_wrong_schema_version(mock_request):
def test_schema_version_1_0_0():
- with requests_mock.mock() as m:
- with open('tests/resources/geolink_v1.0.0.xml', 'rb') as f:
- m.get('http://oereblex.test.com/api/geolinks/1500.xml', content=f.read())
+ with requests_mock.mock() as mock_m:
+ with open('tests/resources/geolink_v1.0.0.xml', 'rb') as file_f:
+ mock_m.get('http://oereblex.test.com/api/geolinks/1500.xml', content=file_f.read())
documents = XML(version=SCHEMA.V1_0_0).from_url('http://oereblex.test.com/api/geolinks/1500.xml')
assert documents[0].cycle == 'cycle'
def test_schema_version_1_1_0():
fmt = '%Y-%m-%d'
- with requests_mock.mock() as m:
- with open('tests/resources/geolink_v1.1.0.xml', 'rb') as f:
- m.get('http://oereblex.test.com/api/geolinks/1500.xml', content=f.read())
+ with requests_mock.mock() as mock_m:
+ with open('tests/resources/geolink_v1.1.0.xml', 'rb') as file_f:
+ mock_m.get('http://oereblex.test.com/api/geolinks/1500.xml', content=file_f.read())
documents = XML(version=SCHEMA.V1_1_0).from_url('http://oereblex.test.com/api/geolinks/1500.xml')
assert documents[0].number == '1A'
assert documents[0].abbreviation == 'abbr'
@@ -177,9 +177,9 @@ def test_schema_version_1_1_0():
def test_schema_version_1_1_1():
- with requests_mock.mock() as m:
- with open('tests/resources/geolink_v1.1.1.xml', 'rb') as f:
- m.get('http://oereblex.test.com/api/geolinks/1500.xml', content=f.read())
+ with requests_mock.mock() as mock_m:
+ with open('tests/resources/geolink_v1.1.1.xml', 'rb') as file_f:
+ mock_m.get('http://oereblex.test.com/api/geolinks/1500.xml', content=file_f.read())
documents = XML(version=SCHEMA.V1_1_1).from_url('http://oereblex.test.com/api/geolinks/1500.xml')
assert documents[0].number == '1A'
assert documents[0].abbreviation == 'abbr'
@@ -188,9 +188,9 @@ def test_schema_version_1_1_1():
def test_schema_version_1_1_1_with_bezirk():
fmt = '%Y-%m-%d'
- with requests_mock.mock() as m:
- with open('tests/resources/geolink_v1.1.1_bezirk.xml', 'rb') as f:
- m.get('http://oereblex.test.com/api/geolinks/1500.xml', content=f.read())
+ with requests_mock.mock() as mock_m:
+ with open('tests/resources/geolink_v1.1.1_bezirk.xml', 'rb') as file_f:
+ mock_m.get('http://oereblex.test.com/api/geolinks/1500.xml', content=file_f.read())
documents = XML(version=SCHEMA.V1_1_1).from_url('http://oereblex.test.com/api/geolinks/1500.xml')
assert documents[0].number == '1A'
assert documents[0].abbreviation == 'abbr'
@@ -199,9 +199,9 @@ def test_schema_version_1_1_1_with_bezirk():
def test_schema_version_1_2_0():
- with requests_mock.mock() as m:
- with open('tests/resources/geolink_v1.2.0.xml', 'rb') as f:
- m.get('http://oereblex.test.com/api/geolinks/1500.xml', content=f.read())
+ with requests_mock.mock() as mock_m:
+ with open('tests/resources/geolink_v1.2.0.xml', 'rb') as file_f:
+ mock_m.get('http://oereblex.test.com/api/geolinks/1500.xml', content=file_f.read())
documents = XML(version=SCHEMA.V1_2_0).from_url('http://oereblex.test.com/api/geolinks/1500.xml')
assert len(documents) == 5
assert documents[-1].doctype == 'notice'
@@ -210,9 +210,9 @@ def test_schema_version_1_2_0():
def test_schema_version_1_2_1():
- with requests_mock.mock() as m:
- with open('tests/resources/geolink_v1.2.1.xml', 'rb') as f:
- m.get('http://oereblex.test.com/api/geolinks/1500.xml', content=f.read())
+ with requests_mock.mock() as mock_m:
+ with open('tests/resources/geolink_v1.2.1.xml', 'rb') as file_f:
+ mock_m.get('http://oereblex.test.com/api/geolinks/1500.xml', content=file_f.read())
documents = XML(version=SCHEMA.V1_2_1).from_url('http://oereblex.test.com/api/geolinks/1500.xml')
assert len(documents) == 5
assert documents[0].municipality == 'Testgemeinde'
@@ -220,9 +220,9 @@ def test_schema_version_1_2_1():
def test_schema_version_1_2_2():
- with requests_mock.mock() as m:
- with open('tests/resources/geolink_v1.2.2.xml', 'rb') as f:
- m.get('http://oereblex.test.com/api/geolinks/1500.xml', content=f.read())
+ with requests_mock.mock() as mock_m:
+ with open('tests/resources/geolink_v1.2.2.xml', 'rb') as file_f:
+ mock_m.get('http://oereblex.test.com/api/geolinks/1500.xml', content=file_f.read())
documents = XML(version=SCHEMA.V1_2_2).from_url('http://oereblex.test.com/api/geolinks/1500.xml')
assert len(documents) == 5
assert documents[0].index is None
@@ -232,9 +232,9 @@ def test_schema_version_1_2_2():
def test_schema_version_1_2_2_prepublink():
- with requests_mock.mock() as m:
- with open('tests/resources/prepublink_v1.2.2.xml', 'rb') as f:
- m.get('http://oereblex.test.com/api/geolinks/1500.xml', content=f.read())
+ with requests_mock.mock() as mock_m:
+ with open('tests/resources/prepublink_v1.2.2.xml', 'rb') as file_f:
+ mock_m.get('http://oereblex.test.com/api/geolinks/1500.xml', content=file_f.read())
documents = XML(version=SCHEMA.V1_2_2).from_url('http://oereblex.test.com/api/geolinks/1500.xml')
assert len(documents) == 6
assert documents[0].index is None
@@ -245,25 +245,25 @@ def test_schema_version_1_2_2_prepublink():
def test_schema_version_1_2_2_faulty_prepublink():
with pytest.raises(xmlschema.XMLSchemaValidationError):
- with requests_mock.mock() as m:
- with open('tests/resources/prepublink_v1.2.2_error_enactment_date.xml', 'rb') as f:
- m.get('http://oereblex.test.com/api/geolinks/1500.xml', content=f.read())
+ with requests_mock.mock() as mock_m:
+ with open('tests/resources/prepublink_v1.2.2_error_enactment_date.xml', 'rb') as file_f:
+ mock_m.get('http://oereblex.test.com/api/geolinks/1500.xml', content=file_f.read())
XML(version=SCHEMA.V1_2_2).from_url('http://oereblex.test.com/api/geolinks/1500.xml')
def test_schema_version_1_2_2_faulty_geolink():
with pytest.raises(xmlschema.XMLSchemaValidationError):
- with requests_mock.mock() as m:
- with open('tests/resources/geolink_v1.2.2_error_status.xml', 'rb') as f:
- m.get('http://oereblex.test.com/api/geolinks/1500.xml', content=f.read())
+ with requests_mock.mock() as mock_m:
+ with open('tests/resources/geolink_v1.2.2_error_status.xml', 'rb') as file_f:
+ mock_m.get('http://oereblex.test.com/api/geolinks/1500.xml', content=file_f.read())
XML(version=SCHEMA.V1_2_2).from_url('http://oereblex.test.com/api/geolinks/1500.xml')
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')
+ with requests_mock.mock() as mock_m:
+ with open('tests/resources/geolink_v1.2.3.xml', 'rb') as file_f:
+ mock_m.get('http://oereblex.test.com/api/geolinks/1500.xml', content=file_f.read())
+ 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
@@ -272,10 +272,10 @@ def test_schema_version_1_2_3():
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')
+ with requests_mock.mock() as mock_m:
+ with open('tests/resources/prepublink_v1.2.3.xml', 'rb') as file_f:
+ mock_m.get('http://oereblex.test.com/api/geolinks/1500.xml', content=file_f.read())
+ 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
@@ -285,24 +285,76 @@ def test_schema_version_1_2_3_prepublink():
def test_schema_version_1_2_3_faulty_prepublink():
with pytest.raises(xmlschema.XMLSchemaValidationError):
- 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')
+ with requests_mock.mock() as mock_m:
+ with open('tests/resources/prepublink_v1.2.3_error_enactment_date.xml', 'rb') as file_f:
+ mock_m.get('http://oereblex.test.com/api/geolinks/1500.xml', content=file_f.read())
+ 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():
with pytest.raises(xmlschema.XMLSchemaValidationError):
- 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')
+ with requests_mock.mock() as mock_m:
+ with open('tests/resources/geolink_v1.2.3_error_status.xml', 'rb') as file_f:
+ mock_m.get('http://oereblex.test.com/api/geolinks/1500.xml', content=file_f.read())
+ XML(version=SCHEMA.V1_2_3).from_url('http://oereblex.test.com/api/geolinks/1500.xml')
+
+
+def test_schema_version_1_2_4():
+ """
+ test of schema version 1.2.4
+ """
+ with requests_mock.mock() as mock_m:
+ with open('tests/resources/geolink_v1.2.4.xml', 'rb') as file_f:
+ mock_m.get('http://oereblex.test.com/api/geolinks/1500.xml', content=file_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():
+ """
+ test of schema version 1.2.4: prepublink
+ """
+ with requests_mock.mock() as mock_m:
+ with open('tests/resources/prepublink_v1.2.4.xml', 'rb') as file_f:
+ mock_m.get('http://oereblex.test.com/api/geolinks/1500.xml', content=file_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():
+ """
+ test of schema version 1.2.4: faulty prepublink
+ """
+ with pytest.raises(xmlschema.XMLSchemaValidationError):
+ with requests_mock.mock() as mock_m:
+ with open('tests/resources/prepublink_v1.2.4_error_enactment_date.xml', 'rb') as file_f:
+ mock_m.get('http://oereblex.test.com/api/geolinks/1500.xml', content=file_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():
+ """
+ test of schema version 1.2.4: faulty geolink
+ """
+ with pytest.raises(xmlschema.XMLSchemaValidationError):
+ with requests_mock.mock() as mock_m:
+ with open('tests/resources/geolink_v1.2.4_error_status.xml', 'rb') as file_f:
+ mock_m.get('http://oereblex.test.com/api/geolinks/1500.xml', content=file_f.read())
+ XML(version=SCHEMA.V1_2_4).from_url('http://oereblex.test.com/api/geolinks/1500.xml')
def test_default_version_with_locale():
- with requests_mock.mock() as m:
- with open('tests/resources/geolink_v1.2.1.xml', 'rb') as f:
- m.get('http://oereblex.test.com/api/geolinks/1500.xml?locale=fr', content=f.read())
+ with requests_mock.mock() as mock_m:
+ with open('tests/resources/geolink_v1.2.1.xml', 'rb') as file_f:
+ mock_m.get('http://oereblex.test.com/api/geolinks/1500.xml?locale=fr', content=file_f.read())
documents = XML().from_url('http://oereblex.test.com/api/geolinks/1500.xml', {'locale': 'fr'})
assert documents[0].number == '1A'
assert documents[0].abbreviation == 'abbr'