From a4f7ccc162ea2e225e19ff5b8c96fa89ada4b878 Mon Sep 17 00:00:00 2001 From: Dragos0000 Date: Wed, 24 Apr 2024 13:18:16 +0100 Subject: [PATCH] added extra feature tests --- tests/features/conftest.py | 10 +++ .../notice_metadata_processor/conftest.py | 6 ++ .../metadata_normaliser_eforms.feature | 30 ++++++++ .../notice_extractor.feature | 7 +- .../test_eForm_notice_eligibility.feature | 11 +++ .../test_eForm_notice_eligibility.py | 68 +++++++++++++++++ .../test_metadata_normaliser_eforms.py | 38 ++++++++++ tests/features/notice_transformer/conftest.py | 15 ++++ ...test_notice_transformer_with_eform.feature | 13 ++++ .../test_notice_transformer_with_eform.py | 74 +++++++++++++++++++ 10 files changed, 268 insertions(+), 4 deletions(-) create mode 100644 tests/features/notice_metadata_processor/metadata_normaliser_eforms.feature create mode 100644 tests/features/notice_metadata_processor/test_eForm_notice_eligibility.feature create mode 100644 tests/features/notice_metadata_processor/test_eForm_notice_eligibility.py create mode 100644 tests/features/notice_metadata_processor/test_metadata_normaliser_eforms.py create mode 100644 tests/features/notice_transformer/test_notice_transformer_with_eform.feature create mode 100644 tests/features/notice_transformer/test_notice_transformer_with_eform.py diff --git a/tests/features/conftest.py b/tests/features/conftest.py index b755701ce..882766d6d 100644 --- a/tests/features/conftest.py +++ b/tests/features/conftest.py @@ -49,6 +49,16 @@ def f03_notice_2020(notice_repository, ted_api_end_point): notice.set_xml_metadata(xml_metadata=XMLMetadata(unique_xpaths=["FAKE_INDEX_XPATHS"])) return notice +@pytest.fixture +def eForm_notice_2023(notice_repository, ted_api_end_point): + notice_search_query = {"query": "ND=17554-2024"} + NoticeFetcher(notice_repository=notice_repository, + ted_api_adapter=TedAPIAdapter(request_api=TedRequestAPI(), + ted_api_url=ted_api_end_point)).fetch_notices_by_query( + query=notice_search_query) + notice = notice_repository.get(reference="17554-2024") + notice.set_xml_metadata(xml_metadata=XMLMetadata(unique_xpaths=["FAKE_INDEX_XPATHS"])) + return notice @pytest.fixture def f18_notice_2022(notice_repository, ted_api_end_point): diff --git a/tests/features/notice_metadata_processor/conftest.py b/tests/features/notice_metadata_processor/conftest.py index 1c48058f4..e73e498e2 100644 --- a/tests/features/notice_metadata_processor/conftest.py +++ b/tests/features/notice_metadata_processor/conftest.py @@ -34,6 +34,12 @@ def normalised_notice(notice_2020): normalise_notice(notice=notice) return notice +@pytest.fixture +def normalised_eForm_notice(indexed_eform_notice_622690): + notice = indexed_eform_notice_622690.copy() + normalise_notice(notice=notice) + return notice + @pytest.fixture def mapping_suite_repository_with_mapping_suite(notice_eligibility_repository_path): diff --git a/tests/features/notice_metadata_processor/metadata_normaliser_eforms.feature b/tests/features/notice_metadata_processor/metadata_normaliser_eforms.feature new file mode 100644 index 000000000..40cadc70e --- /dev/null +++ b/tests/features/notice_metadata_processor/metadata_normaliser_eforms.feature @@ -0,0 +1,30 @@ +Feature: Notice metadata normaliser for eForms + A fetched eForm notice metadata should be normalised + + Scenario Outline: Normalising notice metadata for an eForm + Given a eForm notice + When the normalise process is executed + Then a normalised notice is available + And the notice status is NORMALISED_METADATA + And normalised metadata is available + + Examples: + | metadata | possibly | + | title | True | + | long_title | True | + | notice_publication_number | True | + | publication_date | True | + | ojs_issue_number | True | + | ojs_type | True | + | eforms_subtype | True | + | xsd_version | False | + | original_language | False | + | eform_sdk_version | True | + | notice_source | True | + | document_sent_date | True | + | deadline_for_submission | False | + | notice_type | True | + | form_type | True | + | place_of_performance | True | + | legal_basis_directive | True | + diff --git a/tests/features/notice_metadata_processor/notice_extractor.feature b/tests/features/notice_metadata_processor/notice_extractor.feature index 8e2504eb3..1f7afeff1 100644 --- a/tests/features/notice_metadata_processor/notice_extractor.feature +++ b/tests/features/notice_metadata_processor/notice_extractor.feature @@ -24,8 +24,8 @@ Feature: Notice extractor | deadline_for_submission | | type_of_contract | | type_of_procedure | -# | extracted_notice_type | -# | form_number | + | extracted_notice_type | + | extracted_form_number | | regulation | | type_of_bid | | award_criteria | @@ -33,7 +33,6 @@ Feature: Notice extractor | place_of_performance | | internet_address | | legal_basis_directive | -# | xml_schema | -# | xml_schema_version | + | xml_schema_version | diff --git a/tests/features/notice_metadata_processor/test_eForm_notice_eligibility.feature b/tests/features/notice_metadata_processor/test_eForm_notice_eligibility.feature new file mode 100644 index 000000000..3d4d4e968 --- /dev/null +++ b/tests/features/notice_metadata_processor/test_eForm_notice_eligibility.feature @@ -0,0 +1,11 @@ +Feature: Notice metadata processor for Eforms + The system is able to process TED notice metadata and check eligibility with mapping rules. + + Scenario: Notice eligibility checking for eForms + Given a notice + And the notice has eforms subtype 16 and sdk version 1.7 + And the notice status is NORMALISED + And a mapping suite repository + And a mapping suite for eforms subtype 16 and sdk version 1.7 is available in mapping suite repository + When the notice eligibility checking is executed + Then the notice status is ELIGIBLE_FOR_TRANSFORMATION diff --git a/tests/features/notice_metadata_processor/test_eForm_notice_eligibility.py b/tests/features/notice_metadata_processor/test_eForm_notice_eligibility.py new file mode 100644 index 000000000..d3780062c --- /dev/null +++ b/tests/features/notice_metadata_processor/test_eForm_notice_eligibility.py @@ -0,0 +1,68 @@ +"""Notice metadata processor feature tests.""" + +from pytest_bdd import ( + given, + scenario, + then, + when, +) + +from ted_sws.core.model.notice import Notice, NoticeStatus +from ted_sws.data_manager.adapters.repository_abc import MappingSuiteRepositoryABC +from ted_sws.notice_metadata_processor.services.notice_eligibility import notice_eligibility_checker + + +@scenario('test_eForm_notice_eligibility.feature', 'Notice eligibility checking for eForms') +def test_notice_eligibility_checking_positive(): + """Notice eligibility checking positive.""" + + +@given('a mapping suite for eforms subtype 16 and sdk version 1.7 is available in mapping suite repository', target_fixture="mapping_suite_repository") +def a_mapping_suite_for_f03_is_available_in_mapping_suite_repository(clean_mapping_suite_repository, + mapping_suite_repository_with_mapping_suite): + """a mapping suite for eforms subtype 16 and sdk version 1.7 is available in mapping suite repository.""" + for mapping_suite in mapping_suite_repository_with_mapping_suite.list(): + clean_mapping_suite_repository.add(mapping_suite=mapping_suite) + return clean_mapping_suite_repository + + + +@given('a mapping suite repository') +def a_mapping_suite_repository(clean_mapping_suite_repository): + """a mapping suite repository.""" + assert clean_mapping_suite_repository + assert isinstance(clean_mapping_suite_repository, MappingSuiteRepositoryABC) + + +@given('a notice') +def a_notice(normalised_eForm_notice): + """a notice.""" + assert normalised_eForm_notice + assert isinstance(normalised_eForm_notice, Notice) + + +@given('the notice has eforms subtype 16 and sdk version 1.7') +def the_notice_has_eforms_subtype_and_sdk_version(normalised_eForm_notice): + """the notice has eforms subtype 16 and sdk version 1.7""" + assert normalised_eForm_notice.normalised_metadata.eforms_subtype == "16" + assert normalised_eForm_notice.normalised_metadata.eform_sdk_version == "eforms-sdk-1.7" + + +@given('the notice status is NORMALISED') +def the_notice_status_is_normalised(normalised_eForm_notice): + """the notice status is NORMALISED.""" + assert normalised_eForm_notice.status == NoticeStatus.NORMALISED_METADATA + + +@when('the notice eligibility checking is executed', target_fixture="checked_notice") +def the_notice_eligibility_checking_is_executed(normalised_eForm_notice, mapping_suite_repository): + """the notice eligibility checking is executed.""" + notice_eligibility_checker(notice=normalised_eForm_notice, mapping_suite_repository=mapping_suite_repository) + return normalised_eForm_notice + + +@then('the notice status is ELIGIBLE_FOR_TRANSFORMATION') +def the_notice_status_is_eligible_for_transformation(checked_notice: Notice): + """the notice status is ELIGIBLE_FOR_TRANSFORMATION.""" + assert checked_notice.status == NoticeStatus.ELIGIBLE_FOR_TRANSFORMATION + diff --git a/tests/features/notice_metadata_processor/test_metadata_normaliser_eforms.py b/tests/features/notice_metadata_processor/test_metadata_normaliser_eforms.py new file mode 100644 index 000000000..10f7b194b --- /dev/null +++ b/tests/features/notice_metadata_processor/test_metadata_normaliser_eforms.py @@ -0,0 +1,38 @@ +from pytest_bdd import scenario, given, when, then, parsers + +from ted_sws.core.model.notice import NoticeStatus +from ted_sws.notice_metadata_processor.services.metadata_normalizer import normalise_notice + + +@scenario('metadata_normaliser_eforms.feature', 'Normalising notice metadata for an eForm') +def test_normalise_metadata(): + """normalising metadata""" + + +@given("a eForm notice", target_fixture="notice") +def step_impl(eForm_notice_2023): + return eForm_notice_2023 + + +@when("the normalise process is executed") +def step_impl(notice): + normalise_notice(notice=notice) + + +@then(parsers.parse("a normalised notice {metadata} is {possibly} available")) +def step_impl(notice, metadata, possibly): + metadata_value = notice.normalised_metadata.dict()[metadata] + print(notice.normalised_metadata) + print(metadata) + is_value_there = "True" if metadata_value else "False" + assert is_value_there == possibly + + +@then("the notice status is NORMALISED_METADATA") +def step_impl(notice): + assert notice.status is NoticeStatus.NORMALISED_METADATA + + +@then("normalised metadata is available") +def step_impl(notice): + assert notice.normalised_metadata diff --git a/tests/features/notice_transformer/conftest.py b/tests/features/notice_transformer/conftest.py index db02e3c78..bcfa7c7a0 100644 --- a/tests/features/notice_transformer/conftest.py +++ b/tests/features/notice_transformer/conftest.py @@ -13,6 +13,7 @@ from ted_sws.data_manager.adapters.mapping_suite_repository import MappingSuiteRepositoryMongoDB, \ MappingSuiteRepositoryInFileSystem from ted_sws.data_manager.adapters.notice_repository import NoticeRepository +from ted_sws.notice_metadata_processor.services.metadata_normalizer import normalise_notice from ted_sws.notice_transformer.adapters.rml_mapper import RMLMapper, SerializationFormat from tests import TEST_DATA_PATH from tests.fakes.fake_rml_mapper import FakeRMLMapper @@ -38,6 +39,11 @@ def mapping_suite(mapping_suite_repository, mapping_suite_id) -> MappingSuite: return mapping_suite_repository.get(reference=mapping_suite_id) +@pytest.fixture +def eform_mapping_suite(mapping_suite_repository, mapping_suite_id) -> MappingSuite: + return mapping_suite_repository.get(reference="test_package4") + + @pytest.fixture(scope="function") @mongomock.patch(servers=(('server.example.com', 27017),)) def mongodb_client(): @@ -67,3 +73,12 @@ def transformation_eligible_notice(publicly_available_notice) -> Notice: notice.update_status_to(NoticeStatus.ELIGIBLE_FOR_TRANSFORMATION) notice.update_status_to(NoticeStatus.PREPROCESSED_FOR_TRANSFORMATION) return notice + + +@pytest.fixture(scope="function") +def eform_transformation_eligible_notice(indexed_eform_notice_622690) -> Notice: + notice = indexed_eform_notice_622690.copy() + normalise_notice(notice=notice) + notice.update_status_to(NoticeStatus.ELIGIBLE_FOR_TRANSFORMATION) + notice.update_status_to(NoticeStatus.PREPROCESSED_FOR_TRANSFORMATION) + return notice \ No newline at end of file diff --git a/tests/features/notice_transformer/test_notice_transformer_with_eform.feature b/tests/features/notice_transformer/test_notice_transformer_with_eform.feature new file mode 100644 index 000000000..51e22bbb7 --- /dev/null +++ b/tests/features/notice_transformer/test_notice_transformer_with_eform.feature @@ -0,0 +1,13 @@ +# Created by Stefan at 16.08.2022 +Feature: Notice transformer with eForm + The system is able to transform a notice from XML format in RDF format + + Scenario: Transform a eForm TED notice + Given a eForm notice + And a mapping suite package + And a rml mapper + And given notice is eligible for transformation + And given mapping suite is eligible for notice transformation + When the notice transformation is executed + Then the notice has RDF manifestation + And the notice status is TRANSFORMED \ No newline at end of file diff --git a/tests/features/notice_transformer/test_notice_transformer_with_eform.py b/tests/features/notice_transformer/test_notice_transformer_with_eform.py new file mode 100644 index 000000000..a6d3c3152 --- /dev/null +++ b/tests/features/notice_transformer/test_notice_transformer_with_eform.py @@ -0,0 +1,74 @@ +"""Notice transformer feature tests.""" + +from pytest_bdd import ( + given, + scenario, + then, + when, +) + +from ted_sws.core.model.notice import NoticeStatus, Notice +from ted_sws.core.model.transform import MappingSuite +from ted_sws.data_manager.adapters.repository_abc import NoticeRepositoryABC, MappingSuiteRepositoryABC +from ted_sws.notice_transformer.adapters.rml_mapper import RMLMapperABC +from ted_sws.notice_transformer.services.notice_transformer import transform_notice, transform_notice_by_id + + +@scenario('test_notice_transformer_with_eform.feature', 'Transform a eForm TED notice') +def test_transform_a_ted_notice(): + """Transform a TED notice.""" + + +@given('a mapping suite package') +def a_mapping_suite_package(eform_mapping_suite): + """a mapping suite package.""" + assert eform_mapping_suite + assert isinstance(eform_mapping_suite, MappingSuite) + + +@given('a eForm notice', target_fixture="eligible_for_transformation_eForm_notice") +def a_notice(eform_transformation_eligible_notice): + """a notice.""" + assert eform_transformation_eligible_notice + assert isinstance(eform_transformation_eligible_notice, Notice) + return eform_transformation_eligible_notice + + +@given('a rml mapper') +def a_rml_mapper(rml_mapper): + """a rml mapper.""" + assert rml_mapper + assert isinstance(rml_mapper, RMLMapperABC) + + +@given('given mapping suite is eligible for notice transformation') +def given_mapping_suite_is_eligible_for_notice_transformation(): + """given mapping suite is eligible for notice transformation.""" + + +@given('given notice is eligible for transformation') +def given_notice_is_eligible_for_transformation(eligible_for_transformation_eForm_notice): + """given notice is eligible for transformation.""" + assert eligible_for_transformation_eForm_notice + assert eligible_for_transformation_eForm_notice.status == NoticeStatus.PREPROCESSED_FOR_TRANSFORMATION + + +@when('the notice transformation is executed', target_fixture="transformed_notice") +def the_notice_transformation_is_executed(eligible_for_transformation_eForm_notice, mapping_suite, rml_mapper): + """the notice transformation is executed.""" + transformed_notice = transform_notice(notice=eligible_for_transformation_eForm_notice, mapping_suite=mapping_suite, + rml_mapper=rml_mapper) + return transformed_notice + + +@then('the notice has RDF manifestation') +def the_notice_have_rdf_manifestation(transformed_notice: Notice): + """the notice have RDF manifestation.""" + assert transformed_notice.rdf_manifestation + assert transformed_notice.rdf_manifestation.object_data + + +@then('the notice status is TRANSFORMED') +def the_notice_status_is_transformed(transformed_notice: Notice): + """the notice status is TRANSFORMED.""" + assert transformed_notice.status == NoticeStatus.TRANSFORMED