Skip to content

Commit

Permalink
add tag name / add tests for prepublinks v1.2.5
Browse files Browse the repository at this point in the history
  • Loading branch information
michmuel committed Dec 4, 2024
1 parent 0081889 commit fc4c63f
Show file tree
Hide file tree
Showing 4 changed files with 140 additions and 2 deletions.
2 changes: 1 addition & 1 deletion geolink_formatter/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def from_string(self, xml):
documents = []

# evaluate root element's tag
if root.tag == 'multilang_geolinks':
if root.tag in ['multilang_geolinks', 'multilang_prepublinks']:
for elem in root.iter('geolinks', 'prepublinks'):
documents.extend(self._process_geolinks_prepublinks(elem))
elif root.tag in ['geolinks', 'prepublinks']:
Expand Down
43 changes: 43 additions & 0 deletions tests/resources/prepublink_v1.2.5.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<prepublinks language="de">
<document authority="Gemeindeverwaltung" authority_url="https://www.binningen.ch"
category="main" doctype="prepublication" federal_level="Gemeinde" id="8087"
instance="Gemeinde" language="de" municipality="Binningen"
status="RBG (1) beschlossen, Genehmigungsantrag ausstehend" status_start_date="2024-08-26"
subtype="Zonenplan" title="11/ZPS/2/x_Zone mit Quartierplanpflicht Spiesshöfli"
type="Nutzungsplan">
<file category="main" description="20240826_ERB_Binningen.pdf" href="/api/attachments/19090"
title="20240826_ERB_Binningen.pdf" />
</document>
<document authority="Gemeindeverwaltung" authority_url="https://www.binningen.ch"
category="related" decree_date="2013-09-17" doctype="decree" enactment_date="2013-09-17"
federal_level="Gemeinde" id="1254" language="de" municipality="Binningen"
number="11/ZRS/2/0" title="Zonenreglement Siedlung">
<file category="main" description="11_ZRS_02_00_N_G_2013_1521_oereb.pdf"
href="/api/attachments/18516" title="11_ZRS_02_00_N_G_2013_1521_oereb.pdf" />
</document>
<document abbreviation="RBG" authority="Landeskanzlei;BUD GSK"
authority_url="https://www.baselland.ch/politik-und-behorden/besondere-behoerden/bv-bb/landeskanzlei;https://www.baselland.ch/politik-und-behorden/direktionen/bau-und-umweltschutzdirektion/generalsekretariat"
category="related" decree_date="1998-01-08" doctype="edict" enactment_date="2024-01-01"
federal_level="Kanton" id="3" index="731" language="de" number="400"
title="Raumplanungs- und Baugesetz">
<file category="main" description="400.pdf"
href="https://bl.clex.ch/frontend/versions/pdf_file_with_annex/3813?locale=de"
title="400.pdf" />
</document>
<document abbreviation="RBV" authority="Landeskanzlei"
authority_url="https://www.baselland.ch/politik-und-behorden/besondere-behoerden/bv-bb/landeskanzlei"
category="related" decree_date="1998-10-27" doctype="edict" enactment_date="2024-01-01"
federal_level="Kanton" id="16" index="741" language="de" number="400.11"
title="Verordnung zum Raumplanungs- und Baugesetz">
<file category="main" description="400.11.pdf"
href="https://bl.clex.ch/frontend/versions/pdf_file_with_annex/3836?locale=de"
title="400.11.pdf" />
</document>
<document abbreviation="Raumplanungsgesetz, RPG" authority="Bundeskanzlei"
authority_url="https://www.bk.admin.ch/bk/de/home.html" category="related" doctype="edict"
enactment_date="2019-01-01" federal_level="Bund" id="1" index="10" language="de"
number="700" title="Bundesgesetz über die Raumplanung">
<file category="main" description="700.de.pdf" href="https://www.lexfind.ch/tolv/247302/de"
title="700.de.pdf" />
</document>
</prepublinks>
45 changes: 45 additions & 0 deletions tests/resources/prepublink_v1.2.5_ml.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<multilang_prepublinks>
<prepublinks language="de">
<document authority="Gemeindeverwaltung" authority_url="https://www.binningen.ch"
category="main" doctype="prepublication" federal_level="Gemeinde" id="8087"
instance="Gemeinde" language="de" municipality="Binningen"
status="RBG (1) beschlossen, Genehmigungsantrag ausstehend"
status_start_date="2024-08-26" subtype="Zonenplan"
title="11/ZPS/2/x_Zone mit Quartierplanpflicht Spiesshöfli" type="Nutzungsplan">
<file category="main" description="20240826_ERB_Binningen.pdf"
href="/api/attachments/19090" title="20240826_ERB_Binningen.pdf" />
</document>
<document authority="Gemeindeverwaltung" authority_url="https://www.binningen.ch"
category="related" decree_date="2013-09-17" doctype="decree" enactment_date="2013-09-17"
federal_level="Gemeinde" id="1254" language="de" municipality="Binningen"
number="11/ZRS/2/0" title="Zonenreglement Siedlung">
<file category="main" description="11_ZRS_02_00_N_G_2013_1521_oereb.pdf"
href="/api/attachments/18516" title="11_ZRS_02_00_N_G_2013_1521_oereb.pdf" />
</document>
<document abbreviation="RBG" authority="Landeskanzlei;BUD GSK"
authority_url="https://www.baselland.ch/politik-und-behorden/besondere-behoerden/bv-bb/landeskanzlei;https://www.baselland.ch/politik-und-behorden/direktionen/bau-und-umweltschutzdirektion/generalsekretariat"
category="related" decree_date="1998-01-08" doctype="edict" enactment_date="2024-01-01"
federal_level="Kanton" id="3" index="731" language="de" number="400"
title="Raumplanungs- und Baugesetz">
<file category="main" description="400.pdf"
href="https://bl.clex.ch/frontend/versions/pdf_file_with_annex/3813?locale=de"
title="400.pdf" />
</document>
<document abbreviation="RBV" authority="Landeskanzlei"
authority_url="https://www.baselland.ch/politik-und-behorden/besondere-behoerden/bv-bb/landeskanzlei"
category="related" decree_date="1998-10-27" doctype="edict" enactment_date="2024-01-01"
federal_level="Kanton" id="16" index="741" language="de" number="400.11"
title="Verordnung zum Raumplanungs- und Baugesetz">
<file category="main" description="400.11.pdf"
href="https://bl.clex.ch/frontend/versions/pdf_file_with_annex/3836?locale=de"
title="400.11.pdf" />
</document>
<document abbreviation="Raumplanungsgesetz, RPG" authority="Bundeskanzlei"
authority_url="https://www.bk.admin.ch/bk/de/home.html" category="related"
doctype="edict" enactment_date="2019-01-01" federal_level="Bund" id="1" index="10"
language="de" number="700" title="Bundesgesetz über die Raumplanung">
<file category="main" description="700.de.pdf"
href="https://www.lexfind.ch/tolv/247302/de" title="700.de.pdf" />
</document>
</prepublinks>
</multilang_prepublinks>
52 changes: 51 additions & 1 deletion tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -375,11 +375,13 @@ def test_schema_version_1_2_5():
assert documents[-3].id == '11'
assert documents[-2].id == '13'
assert documents[-1].id == '14'
assert documents[0].language_document == 'de'
assert documents[0].language_link == 'de'


def test_schema_version_1_2_5_ml():
"""
test of schema version 1.2.5
test of schema version 1.2.5 multilang
"""
with requests_mock.mock() as mock_m:
with open('tests/resources/geolink_v1.2.5_ml.xml', 'rb') as file_f:
Expand All @@ -398,6 +400,54 @@ def test_schema_version_1_2_5_ml():
assert documents[-3].id == '11'
assert documents[-2].id == '13'
assert documents[-1].id == '14'
assert documents[0].language_document == 'de'
assert documents[0].language_link == 'de'
assert documents[2].language_document == 'de'
assert documents[2].language_link == 'de'
assert documents[12].language_document == 'de'
assert documents[12].language_link == 'rm'
assert documents[14].language_document == 'rm'
assert documents[14].language_link == 'rm'
assert documents[24].language_document == 'de'
assert documents[24].language_link == 'it'
assert documents[26].language_document == 'it'
assert documents[26].language_link == 'it'


def test_schema_version_1_2_5_prepublink():
"""
test of schema version 1.2.5: prepublink
"""
with requests_mock.mock() as mock_m:
with open('tests/resources/prepublink_v1.2.5.xml', 'rb') as file_f:
mock_m.get('http://oereblex.test.com/api/prepubs/1500.xml', content=file_f.read())
documents = XML(version=SCHEMA.V1_2_5).from_url('http://oereblex.test.com/api/prepubs/1500.xml')
assert len(documents) == 5
assert documents[0].index is None
assert documents[1].index is None
assert documents[-3].index == 731
assert documents[-2].index == 741
assert documents[-1].index == 10
assert documents[0].language_document == 'de'
assert documents[0].language_link == 'de'


def test_schema_version_1_2_5_prepublink_ml():
"""
test of schema version 1.2.5: prepublink multilang
"""
with requests_mock.mock() as mock_m:
with open('tests/resources/prepublink_v1.2.5_ml.xml', 'rb') as file_f:
mock_m.get('http://oereblex.test.com/api/prepubs/1500.xml', content=file_f.read())
documents = XML(version=SCHEMA.V1_2_5).from_url('http://oereblex.test.com/api/prepubs/1500.xml')
assert len(documents) == 5
assert documents[0].index is None
assert documents[1].index is None
assert documents[-3].index == 731
assert documents[-2].index == 741
assert documents[-1].index == 10
assert documents[0].language_document == 'de'
assert documents[0].language_link == 'de'


def test_default_version_with_locale():
Expand Down

0 comments on commit fc4c63f

Please sign in to comment.