Skip to content

Commit

Permalink
fix variable names
Browse files Browse the repository at this point in the history
  • Loading branch information
michmuel committed Jan 8, 2024
1 parent f78f8c1 commit 730cf42
Showing 1 changed file with 40 additions and 40 deletions.
80 changes: 40 additions & 40 deletions tests/test_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -136,8 +136,8 @@ def test_xml_from_url_invalid():


def test_xml_from_url_error():
with requests_mock.mock() as mm:
mm.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')

Expand All @@ -158,28 +158,28 @@ def test_wrong_schema_version(mock_request):


def test_schema_version_1_0_0():
with requests_mock.mock() as mm:
with requests_mock.mock() as mock_m:
with open('tests/resources/geolink_v1.0.0.xml', 'rb') as f:
mm.get('http://oereblex.test.com/api/geolinks/1500.xml', content=f.read())
mock_m.get('http://oereblex.test.com/api/geolinks/1500.xml', content=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 mm:
with requests_mock.mock() as mock_m:
with open('tests/resources/geolink_v1.1.0.xml', 'rb') as f:
mm.get('http://oereblex.test.com/api/geolinks/1500.xml', content=f.read())
mock_m.get('http://oereblex.test.com/api/geolinks/1500.xml', content=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'
assert documents[0].abrogation_date.strftime(fmt) == '2008-12-31'


def test_schema_version_1_1_1():
with requests_mock.mock() as mm:
with requests_mock.mock() as mock_m:
with open('tests/resources/geolink_v1.1.1.xml', 'rb') as f:
mm.get('http://oereblex.test.com/api/geolinks/1500.xml', content=f.read())
mock_m.get('http://oereblex.test.com/api/geolinks/1500.xml', content=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'
Expand All @@ -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 mm:
with requests_mock.mock() as mock_m:
with open('tests/resources/geolink_v1.1.1_bezirk.xml', 'rb') as f:
mm.get('http://oereblex.test.com/api/geolinks/1500.xml', content=f.read())
mock_m.get('http://oereblex.test.com/api/geolinks/1500.xml', content=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'
Expand All @@ -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 mm:
with requests_mock.mock() as mock_m:
with open('tests/resources/geolink_v1.2.0.xml', 'rb') as f:
mm.get('http://oereblex.test.com/api/geolinks/1500.xml', content=f.read())
mock_m.get('http://oereblex.test.com/api/geolinks/1500.xml', content=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'
Expand All @@ -210,19 +210,19 @@ def test_schema_version_1_2_0():


def test_schema_version_1_2_1():
with requests_mock.mock() as mm:
with requests_mock.mock() as mock_m:
with open('tests/resources/geolink_v1.2.1.xml', 'rb') as f:
mm.get('http://oereblex.test.com/api/geolinks/1500.xml', content=f.read())
mock_m.get('http://oereblex.test.com/api/geolinks/1500.xml', content=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'
assert documents[1].municipality is None


def test_schema_version_1_2_2():
with requests_mock.mock() as mm:
with requests_mock.mock() as mock_m:
with open('tests/resources/geolink_v1.2.2.xml', 'rb') as f:
mm.get('http://oereblex.test.com/api/geolinks/1500.xml', content=f.read())
mock_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')
assert len(documents) == 5
assert documents[0].index is None
Expand All @@ -232,9 +232,9 @@ def test_schema_version_1_2_2():


def test_schema_version_1_2_2_prepublink():
with requests_mock.mock() as mm:
with requests_mock.mock() as mock_m:
with open('tests/resources/prepublink_v1.2.2.xml', 'rb') as f:
mm.get('http://oereblex.test.com/api/geolinks/1500.xml', content=f.read())
mock_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')
assert len(documents) == 6
assert documents[0].index is None
Expand All @@ -245,24 +245,24 @@ 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 mm:
with requests_mock.mock() as mock_m:
with open('tests/resources/prepublink_v1.2.2_error_enactment_date.xml', 'rb') as f:
mm.get('http://oereblex.test.com/api/geolinks/1500.xml', content=f.read())
mock_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')


def test_schema_version_1_2_2_faulty_geolink():
with pytest.raises(xmlschema.XMLSchemaValidationError):
with requests_mock.mock() as mm:
with requests_mock.mock() as mock_m:
with open('tests/resources/geolink_v1.2.2_error_status.xml', 'rb') as f:
mm.get('http://oereblex.test.com/api/geolinks/1500.xml', content=f.read())
mock_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')


def test_schema_version_1_2_3():
with requests_mock.mock() as mm:
with requests_mock.mock() as mock_m:
with open('tests/resources/geolink_v1.2.3.xml', 'rb') as f:
mm.get('http://oereblex.test.com/api/geolinks/1500.xml', content=f.read())
mock_m.get('http://oereblex.test.com/api/geolinks/1500.xml', content=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
Expand All @@ -272,9 +272,9 @@ def test_schema_version_1_2_3():


def test_schema_version_1_2_3_prepublink():
with requests_mock.mock() as mm:
with requests_mock.mock() as mock_m:
with open('tests/resources/prepublink_v1.2.3.xml', 'rb') as f:
mm.get('http://oereblex.test.com/api/geolinks/1500.xml', content=f.read())
mock_m.get('http://oereblex.test.com/api/geolinks/1500.xml', content=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
Expand All @@ -285,24 +285,24 @@ 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 mm:
with requests_mock.mock() as mock_m:
with open('tests/resources/prepublink_v1.2.3_error_enactment_date.xml', 'rb') as f:
mm.get('http://oereblex.test.com/api/geolinks/1500.xml', content=f.read())
mock_m.get('http://oereblex.test.com/api/geolinks/1500.xml', content=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 mm:
with requests_mock.mock() as mock_m:
with open('tests/resources/geolink_v1.2.3_error_status.xml', 'rb') as f:
mm.get('http://oereblex.test.com/api/geolinks/1500.xml', content=f.read())
mock_m.get('http://oereblex.test.com/api/geolinks/1500.xml', content=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():
with requests_mock.mock() as mm:
with requests_mock.mock() as mock_m:
with open('tests/resources/geolink_v1.2.4.xml', 'rb') as f:
mm.get('http://oereblex.test.com/api/geolinks/1500.xml', content=f.read())
mock_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
Expand All @@ -312,9 +312,9 @@ def test_schema_version_1_2_4():


def test_schema_version_1_2_4_prepublink():
with requests_mock.mock() as mm:
with requests_mock.mock() as mock_m:
with open('tests/resources/prepublink_v1.2.4.xml', 'rb') as f:
mm.get('http://oereblex.test.com/api/geolinks/1500.xml', content=f.read())
mock_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
Expand All @@ -325,24 +325,24 @@ def test_schema_version_1_2_4_prepublink():

def test_schema_version_1_2_4_faulty_prepublink():
with pytest.raises(xmlschema.XMLSchemaValidationError):
with requests_mock.mock() as mm:
with requests_mock.mock() as mock_m:
with open('tests/resources/prepublink_v1.2.4_error_enactment_date.xml', 'rb') as f:
mm.get('http://oereblex.test.com/api/geolinks/1500.xml', content=f.read())
mock_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 mm:
with requests_mock.mock() as mock_m:
with open('tests/resources/geolink_v1.2.4_error_status.xml', 'rb') as f:
mm.get('http://oereblex.test.com/api/geolinks/1500.xml', content=f.read())
mock_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():
with requests_mock.mock() as mm:
with requests_mock.mock() as mock_m:
with open('tests/resources/geolink_v1.2.1.xml', 'rb') as f:
mm.get('http://oereblex.test.com/api/geolinks/1500.xml?locale=fr', content=f.read())
mock_m.get('http://oereblex.test.com/api/geolinks/1500.xml?locale=fr', content=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'
Expand Down

0 comments on commit 730cf42

Please sign in to comment.