Skip to content

Commit

Permalink
add tests for correct sorting of extract_indexes
Browse files Browse the repository at this point in the history
  • Loading branch information
mki-c2c committed Sep 12, 2023
1 parent 18150ba commit 85d3982
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 1 deletion.
50 changes: 49 additions & 1 deletion tests/core/readers/test_disclaimer.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,14 +27,45 @@ def disclaimer_data(dbsession, transact):
'it': u'Il catasto dei siti inquinati (CSIN) è stato elaborato sulla \
base dei criteri definiti dall ...',
'rm': u'',
}
},
'extract_index': 2,
})
]
dbsession.add_all(disclaimers)
dbsession.flush()
yield disclaimers


@pytest.fixture(params=[1, 3])
def multi_disclaimer_data(request, dbsession, transact, disclaimer_data):
from pyramid_oereb.contrib.data_sources.standard.models.main import Disclaimer
del transact
disclaimers = [
Disclaimer(**{
'id': 2,
'title': {
'de': u'Haftungsausschluss Kataster der belasteten Standorte V2',
'fr': u'Clause de non-responsabilité du cadastre des sites pollués (CSP) V2',
'it': u'Clausola di esclusione della responsabilità ... V2',
'rm': u''
},
'content': {
'de': u'Der Kataster der belasteten Standorte (KbS) \
wurde anhand der vom Bundesamt für Umwelt BAFU fe ...',
'fr': u'Le cadastre des sites pollués (CSP) est établi d’après \
les critères émis par l’Office fédéral ...',
'it': u'Il catasto dei siti inquinati (CSIN) è stato elaborato sulla \
base dei criteri definiti dall ...',
'rm': u'',
},
'extract_index': request.param,
})
]
dbsession.add_all(disclaimers)
dbsession.flush()
yield disclaimer_data + disclaimers


@pytest.mark.run(order=2)
def test_init(pyramid_oereb_test_config):
reader = DisclaimerReader(
Expand All @@ -58,3 +89,20 @@ def test_read(pyramid_oereb_test_config, disclaimer_data):
assert len(results[0].content) == len(disclaimer_data[0].content)
assert 'du cadastre des sites' in results[0].title['fr']
assert 'Kataster der belasteten Standorte' in results[0].content['de']


@pytest.mark.run(order=2)
def test_sort(pyramid_oereb_test_config, multi_disclaimer_data):
reader = DisclaimerReader(
pyramid_oereb_test_config.get_disclaimer_config().get('source').get('class'),
**pyramid_oereb_test_config.get_disclaimer_config().get('source').get('params')
)
results = reader.read()
assert isinstance(results, list)
assert len(results) == len(multi_disclaimer_data)
assert isinstance(results[0], DisclaimerRecord)
assert len(results[0].title) == len(multi_disclaimer_data[0].title)
assert len(results[0].content) == len(multi_disclaimer_data[0].content)
assert 'du cadastre des sites' in results[0].title['fr']
assert 'Kataster der belasteten Standorte' in results[0].content['de']
assert sorted(r.extract_index for r in results) == [r.extract_index for r in results]
76 changes: 76 additions & 0 deletions tests/core/readers/test_general_information.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# -*- coding: utf-8 -*-
import pytest

from pyramid_oereb.core.sources import Base
from pyramid_oereb.core.readers.general_information import GeneralInformationReader
from pyramid_oereb.core.records.general_information import GeneralInformationRecord


@pytest.fixture
def general_information_data(dbsession, transact):
from pyramid_oereb.contrib.data_sources.standard.models.main import GeneralInformation
del transact
general_information = [
GeneralInformation(**{
'id': 1,
'title': {
'de': u'GI1',
},
'content': {
'de': u'General Information # 1',
'fr': u'Information Generale #1',
},
'extract_index': 2,
}),
GeneralInformation(**{
'id': 2,
'title': {
'de': u'GI2',
},
'content': {
'de': u'General Information # 2',
'fr': u'Information Generale #2',
},
'extract_index': 3,
}),
GeneralInformation(**{
'id': 3,
'title': {
'de': u'GI3',
},
'content': {
'de': u'General Information # 3',
'fr': u'Information Generale #3',
},
'extract_index': 1,
})
]
dbsession.add_all(general_information)
dbsession.flush()
yield general_information


@pytest.mark.run(order=2)
def test_init(pyramid_oereb_test_config):
reader = GeneralInformationReader(
pyramid_oereb_test_config.get_info_config().get('source').get('class'),
**pyramid_oereb_test_config.get_info_config().get('source').get('params')
)
assert isinstance(reader._source_, Base)


@pytest.mark.run(order=2)
def test_read(pyramid_oereb_test_config, general_information_data):
reader = GeneralInformationReader(
pyramid_oereb_test_config.get_info_config().get('source').get('class'),
**pyramid_oereb_test_config.get_info_config().get('source').get('params')
)
results = reader.read()
assert isinstance(results, list)
assert len(results) == len(general_information_data)
assert isinstance(results[0], GeneralInformationRecord)
assert len(results[0].title) == len(general_information_data[0].title)
assert len(results[0].content) == len(general_information_data[0].content)
assert 'GI3' == results[0].title['de']
assert 'Information Generale #1' == results[1].content['fr']
assert sorted(r.extract_index for r in results) == [r.extract_index for r in results]

0 comments on commit 85d3982

Please sign in to comment.