From 85d3982faa58ad300f73c8dfbf04ace4e37c5dcf Mon Sep 17 00:00:00 2001 From: Moritz Kirmse Date: Tue, 12 Sep 2023 11:48:45 +0200 Subject: [PATCH] add tests for correct sorting of extract_indexes --- tests/core/readers/test_disclaimer.py | 50 +++++++++++- .../core/readers/test_general_information.py | 76 +++++++++++++++++++ 2 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 tests/core/readers/test_general_information.py diff --git a/tests/core/readers/test_disclaimer.py b/tests/core/readers/test_disclaimer.py index 64bb6b7805..e475526ef1 100644 --- a/tests/core/readers/test_disclaimer.py +++ b/tests/core/readers/test_disclaimer.py @@ -27,7 +27,8 @@ 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) @@ -35,6 +36,36 @@ def disclaimer_data(dbsession, transact): 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( @@ -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] diff --git a/tests/core/readers/test_general_information.py b/tests/core/readers/test_general_information.py new file mode 100644 index 0000000000..3f83c134c5 --- /dev/null +++ b/tests/core/readers/test_general_information.py @@ -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]