Skip to content

Commit a4f7ccc

Browse files
committed
added extra feature tests
1 parent bc409c7 commit a4f7ccc

10 files changed

Lines changed: 268 additions & 4 deletions

tests/features/conftest.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,16 @@ def f03_notice_2020(notice_repository, ted_api_end_point):
4949
notice.set_xml_metadata(xml_metadata=XMLMetadata(unique_xpaths=["FAKE_INDEX_XPATHS"]))
5050
return notice
5151

52+
@pytest.fixture
53+
def eForm_notice_2023(notice_repository, ted_api_end_point):
54+
notice_search_query = {"query": "ND=17554-2024"}
55+
NoticeFetcher(notice_repository=notice_repository,
56+
ted_api_adapter=TedAPIAdapter(request_api=TedRequestAPI(),
57+
ted_api_url=ted_api_end_point)).fetch_notices_by_query(
58+
query=notice_search_query)
59+
notice = notice_repository.get(reference="17554-2024")
60+
notice.set_xml_metadata(xml_metadata=XMLMetadata(unique_xpaths=["FAKE_INDEX_XPATHS"]))
61+
return notice
5262

5363
@pytest.fixture
5464
def f18_notice_2022(notice_repository, ted_api_end_point):

tests/features/notice_metadata_processor/conftest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,12 @@ def normalised_notice(notice_2020):
3434
normalise_notice(notice=notice)
3535
return notice
3636

37+
@pytest.fixture
38+
def normalised_eForm_notice(indexed_eform_notice_622690):
39+
notice = indexed_eform_notice_622690.copy()
40+
normalise_notice(notice=notice)
41+
return notice
42+
3743

3844
@pytest.fixture
3945
def mapping_suite_repository_with_mapping_suite(notice_eligibility_repository_path):
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
Feature: Notice metadata normaliser for eForms
2+
A fetched eForm notice metadata should be normalised
3+
4+
Scenario Outline: Normalising notice metadata for an eForm
5+
Given a eForm notice
6+
When the normalise process is executed
7+
Then a normalised notice <metadata> is <possibly> available
8+
And the notice status is NORMALISED_METADATA
9+
And normalised metadata is available
10+
11+
Examples:
12+
| metadata | possibly |
13+
| title | True |
14+
| long_title | True |
15+
| notice_publication_number | True |
16+
| publication_date | True |
17+
| ojs_issue_number | True |
18+
| ojs_type | True |
19+
| eforms_subtype | True |
20+
| xsd_version | False |
21+
| original_language | False |
22+
| eform_sdk_version | True |
23+
| notice_source | True |
24+
| document_sent_date | True |
25+
| deadline_for_submission | False |
26+
| notice_type | True |
27+
| form_type | True |
28+
| place_of_performance | True |
29+
| legal_basis_directive | True |
30+

tests/features/notice_metadata_processor/notice_extractor.feature

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,15 @@ Feature: Notice extractor
2424
| deadline_for_submission |
2525
| type_of_contract |
2626
| type_of_procedure |
27-
# | extracted_notice_type |
28-
# | form_number |
27+
| extracted_notice_type |
28+
| extracted_form_number |
2929
| regulation |
3030
| type_of_bid |
3131
| award_criteria |
3232
| common_procurement |
3333
| place_of_performance |
3434
| internet_address |
3535
| legal_basis_directive |
36-
# | xml_schema |
37-
# | xml_schema_version |
36+
| xml_schema_version |
3837

3938

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Feature: Notice metadata processor for Eforms
2+
The system is able to process TED notice metadata and check eligibility with mapping rules.
3+
4+
Scenario: Notice eligibility checking for eForms
5+
Given a notice
6+
And the notice has eforms subtype 16 and sdk version 1.7
7+
And the notice status is NORMALISED
8+
And a mapping suite repository
9+
And a mapping suite for eforms subtype 16 and sdk version 1.7 is available in mapping suite repository
10+
When the notice eligibility checking is executed
11+
Then the notice status is ELIGIBLE_FOR_TRANSFORMATION
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
"""Notice metadata processor feature tests."""
2+
3+
from pytest_bdd import (
4+
given,
5+
scenario,
6+
then,
7+
when,
8+
)
9+
10+
from ted_sws.core.model.notice import Notice, NoticeStatus
11+
from ted_sws.data_manager.adapters.repository_abc import MappingSuiteRepositoryABC
12+
from ted_sws.notice_metadata_processor.services.notice_eligibility import notice_eligibility_checker
13+
14+
15+
@scenario('test_eForm_notice_eligibility.feature', 'Notice eligibility checking for eForms')
16+
def test_notice_eligibility_checking_positive():
17+
"""Notice eligibility checking positive."""
18+
19+
20+
@given('a mapping suite for eforms subtype 16 and sdk version 1.7 is available in mapping suite repository', target_fixture="mapping_suite_repository")
21+
def a_mapping_suite_for_f03_is_available_in_mapping_suite_repository(clean_mapping_suite_repository,
22+
mapping_suite_repository_with_mapping_suite):
23+
"""a mapping suite for eforms subtype 16 and sdk version 1.7 is available in mapping suite repository."""
24+
for mapping_suite in mapping_suite_repository_with_mapping_suite.list():
25+
clean_mapping_suite_repository.add(mapping_suite=mapping_suite)
26+
return clean_mapping_suite_repository
27+
28+
29+
30+
@given('a mapping suite repository')
31+
def a_mapping_suite_repository(clean_mapping_suite_repository):
32+
"""a mapping suite repository."""
33+
assert clean_mapping_suite_repository
34+
assert isinstance(clean_mapping_suite_repository, MappingSuiteRepositoryABC)
35+
36+
37+
@given('a notice')
38+
def a_notice(normalised_eForm_notice):
39+
"""a notice."""
40+
assert normalised_eForm_notice
41+
assert isinstance(normalised_eForm_notice, Notice)
42+
43+
44+
@given('the notice has eforms subtype 16 and sdk version 1.7')
45+
def the_notice_has_eforms_subtype_and_sdk_version(normalised_eForm_notice):
46+
"""the notice has eforms subtype 16 and sdk version 1.7"""
47+
assert normalised_eForm_notice.normalised_metadata.eforms_subtype == "16"
48+
assert normalised_eForm_notice.normalised_metadata.eform_sdk_version == "eforms-sdk-1.7"
49+
50+
51+
@given('the notice status is NORMALISED')
52+
def the_notice_status_is_normalised(normalised_eForm_notice):
53+
"""the notice status is NORMALISED."""
54+
assert normalised_eForm_notice.status == NoticeStatus.NORMALISED_METADATA
55+
56+
57+
@when('the notice eligibility checking is executed', target_fixture="checked_notice")
58+
def the_notice_eligibility_checking_is_executed(normalised_eForm_notice, mapping_suite_repository):
59+
"""the notice eligibility checking is executed."""
60+
notice_eligibility_checker(notice=normalised_eForm_notice, mapping_suite_repository=mapping_suite_repository)
61+
return normalised_eForm_notice
62+
63+
64+
@then('the notice status is ELIGIBLE_FOR_TRANSFORMATION')
65+
def the_notice_status_is_eligible_for_transformation(checked_notice: Notice):
66+
"""the notice status is ELIGIBLE_FOR_TRANSFORMATION."""
67+
assert checked_notice.status == NoticeStatus.ELIGIBLE_FOR_TRANSFORMATION
68+
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from pytest_bdd import scenario, given, when, then, parsers
2+
3+
from ted_sws.core.model.notice import NoticeStatus
4+
from ted_sws.notice_metadata_processor.services.metadata_normalizer import normalise_notice
5+
6+
7+
@scenario('metadata_normaliser_eforms.feature', 'Normalising notice metadata for an eForm')
8+
def test_normalise_metadata():
9+
"""normalising metadata"""
10+
11+
12+
@given("a eForm notice", target_fixture="notice")
13+
def step_impl(eForm_notice_2023):
14+
return eForm_notice_2023
15+
16+
17+
@when("the normalise process is executed")
18+
def step_impl(notice):
19+
normalise_notice(notice=notice)
20+
21+
22+
@then(parsers.parse("a normalised notice {metadata} is {possibly} available"))
23+
def step_impl(notice, metadata, possibly):
24+
metadata_value = notice.normalised_metadata.dict()[metadata]
25+
print(notice.normalised_metadata)
26+
print(metadata)
27+
is_value_there = "True" if metadata_value else "False"
28+
assert is_value_there == possibly
29+
30+
31+
@then("the notice status is NORMALISED_METADATA")
32+
def step_impl(notice):
33+
assert notice.status is NoticeStatus.NORMALISED_METADATA
34+
35+
36+
@then("normalised metadata is available")
37+
def step_impl(notice):
38+
assert notice.normalised_metadata

tests/features/notice_transformer/conftest.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from ted_sws.data_manager.adapters.mapping_suite_repository import MappingSuiteRepositoryMongoDB, \
1414
MappingSuiteRepositoryInFileSystem
1515
from ted_sws.data_manager.adapters.notice_repository import NoticeRepository
16+
from ted_sws.notice_metadata_processor.services.metadata_normalizer import normalise_notice
1617
from ted_sws.notice_transformer.adapters.rml_mapper import RMLMapper, SerializationFormat
1718
from tests import TEST_DATA_PATH
1819
from tests.fakes.fake_rml_mapper import FakeRMLMapper
@@ -38,6 +39,11 @@ def mapping_suite(mapping_suite_repository, mapping_suite_id) -> MappingSuite:
3839
return mapping_suite_repository.get(reference=mapping_suite_id)
3940

4041

42+
@pytest.fixture
43+
def eform_mapping_suite(mapping_suite_repository, mapping_suite_id) -> MappingSuite:
44+
return mapping_suite_repository.get(reference="test_package4")
45+
46+
4147
@pytest.fixture(scope="function")
4248
@mongomock.patch(servers=(('server.example.com', 27017),))
4349
def mongodb_client():
@@ -67,3 +73,12 @@ def transformation_eligible_notice(publicly_available_notice) -> Notice:
6773
notice.update_status_to(NoticeStatus.ELIGIBLE_FOR_TRANSFORMATION)
6874
notice.update_status_to(NoticeStatus.PREPROCESSED_FOR_TRANSFORMATION)
6975
return notice
76+
77+
78+
@pytest.fixture(scope="function")
79+
def eform_transformation_eligible_notice(indexed_eform_notice_622690) -> Notice:
80+
notice = indexed_eform_notice_622690.copy()
81+
normalise_notice(notice=notice)
82+
notice.update_status_to(NoticeStatus.ELIGIBLE_FOR_TRANSFORMATION)
83+
notice.update_status_to(NoticeStatus.PREPROCESSED_FOR_TRANSFORMATION)
84+
return notice
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Created by Stefan at 16.08.2022
2+
Feature: Notice transformer with eForm
3+
The system is able to transform a notice from XML format in RDF format
4+
5+
Scenario: Transform a eForm TED notice
6+
Given a eForm notice
7+
And a mapping suite package
8+
And a rml mapper
9+
And given notice is eligible for transformation
10+
And given mapping suite is eligible for notice transformation
11+
When the notice transformation is executed
12+
Then the notice has RDF manifestation
13+
And the notice status is TRANSFORMED
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
"""Notice transformer feature tests."""
2+
3+
from pytest_bdd import (
4+
given,
5+
scenario,
6+
then,
7+
when,
8+
)
9+
10+
from ted_sws.core.model.notice import NoticeStatus, Notice
11+
from ted_sws.core.model.transform import MappingSuite
12+
from ted_sws.data_manager.adapters.repository_abc import NoticeRepositoryABC, MappingSuiteRepositoryABC
13+
from ted_sws.notice_transformer.adapters.rml_mapper import RMLMapperABC
14+
from ted_sws.notice_transformer.services.notice_transformer import transform_notice, transform_notice_by_id
15+
16+
17+
@scenario('test_notice_transformer_with_eform.feature', 'Transform a eForm TED notice')
18+
def test_transform_a_ted_notice():
19+
"""Transform a TED notice."""
20+
21+
22+
@given('a mapping suite package')
23+
def a_mapping_suite_package(eform_mapping_suite):
24+
"""a mapping suite package."""
25+
assert eform_mapping_suite
26+
assert isinstance(eform_mapping_suite, MappingSuite)
27+
28+
29+
@given('a eForm notice', target_fixture="eligible_for_transformation_eForm_notice")
30+
def a_notice(eform_transformation_eligible_notice):
31+
"""a notice."""
32+
assert eform_transformation_eligible_notice
33+
assert isinstance(eform_transformation_eligible_notice, Notice)
34+
return eform_transformation_eligible_notice
35+
36+
37+
@given('a rml mapper')
38+
def a_rml_mapper(rml_mapper):
39+
"""a rml mapper."""
40+
assert rml_mapper
41+
assert isinstance(rml_mapper, RMLMapperABC)
42+
43+
44+
@given('given mapping suite is eligible for notice transformation')
45+
def given_mapping_suite_is_eligible_for_notice_transformation():
46+
"""given mapping suite is eligible for notice transformation."""
47+
48+
49+
@given('given notice is eligible for transformation')
50+
def given_notice_is_eligible_for_transformation(eligible_for_transformation_eForm_notice):
51+
"""given notice is eligible for transformation."""
52+
assert eligible_for_transformation_eForm_notice
53+
assert eligible_for_transformation_eForm_notice.status == NoticeStatus.PREPROCESSED_FOR_TRANSFORMATION
54+
55+
56+
@when('the notice transformation is executed', target_fixture="transformed_notice")
57+
def the_notice_transformation_is_executed(eligible_for_transformation_eForm_notice, mapping_suite, rml_mapper):
58+
"""the notice transformation is executed."""
59+
transformed_notice = transform_notice(notice=eligible_for_transformation_eForm_notice, mapping_suite=mapping_suite,
60+
rml_mapper=rml_mapper)
61+
return transformed_notice
62+
63+
64+
@then('the notice has RDF manifestation')
65+
def the_notice_have_rdf_manifestation(transformed_notice: Notice):
66+
"""the notice have RDF manifestation."""
67+
assert transformed_notice.rdf_manifestation
68+
assert transformed_notice.rdf_manifestation.object_data
69+
70+
71+
@then('the notice status is TRANSFORMED')
72+
def the_notice_status_is_transformed(transformed_notice: Notice):
73+
"""the notice status is TRANSFORMED."""
74+
assert transformed_notice.status == NoticeStatus.TRANSFORMED

0 commit comments

Comments
 (0)