Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added extra feature tests #535

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions tests/features/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
6 changes: 6 additions & 0 deletions tests/features/notice_metadata_processor/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -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 <metadata> is <possibly> 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 |

Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,15 @@ 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 |
| common_procurement |
| place_of_performance |
| internet_address |
| legal_basis_directive |
# | xml_schema |
# | xml_schema_version |
| xml_schema_version |


Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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

Original file line number Diff line number Diff line change
@@ -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
15 changes: 15 additions & 0 deletions tests/features/notice_transformer/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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():
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -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
Loading