Skip to content

Commit 9f562a0

Browse files
Merge pull request #223 from OP-TED/feature/TED-593
Feature/ted 593
2 parents 08ad406 + 3c71f63 commit 9f562a0

72 files changed

Lines changed: 2330 additions & 159 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ test-unit:
3737

3838
test-features:
3939
@ echo -e "$(BUILD_PRINT)Gherkin Features Testing ...$(END_BUILD_PRINT)"
40-
# @ tox -e features
40+
@ tox -e features
4141

4242
test-e2e:
4343
@ echo -e "$(BUILD_PRINT)End to End Testing ...$(END_BUILD_PRINT)"

ted_sws/notice_transformer/services/notice_transformer.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import abc
21
import tempfile
32
from pathlib import Path
43

tests/features/__init__.py

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +0,0 @@
1-
#!/usr/bin/python3
2-
3-
# __init__.py
4-
# Date: 03/02/2022
5-
# Author: Eugeniu Costetchi
6-
# Email: costezki.eugen@gmail.com
7-
8-
""" """
9-
10-
11-
def str2bool(value: str) -> bool:
12-
"""
13-
Parse a string value and cast it into its boolean value
14-
:param value:
15-
:return:
16-
"""
17-
if value in ["y", "yes", "t", "true", "on", "1"]: return True
18-
if value in ["n", "no", "f", "false", "off", "0"]: return False
19-
raise ValueError("boolean value unrecognised")

tests/features/conftest.py

Lines changed: 65 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,103 @@
1+
import mongomock
2+
import pymongo
13
import pytest
2-
from pymongo import MongoClient
34

45
from ted_sws import config
5-
from ted_sws.core.model.metadata import XMLMetadata
6-
from ted_sws.data_manager.adapters.mapping_suite_repository import MappingSuiteRepositoryInFileSystem
6+
from ted_sws.core.model.manifestation import METSManifestation, RDFManifestation, SHACLTestSuiteValidationReport, \
7+
SPARQLTestSuiteValidationReport
8+
from ted_sws.core.model.metadata import NormalisedMetadata, XMLMetadata
9+
from ted_sws.core.model.notice import NoticeStatus, Notice
710
from ted_sws.data_manager.adapters.notice_repository import NoticeRepository
8-
911
from ted_sws.notice_fetcher.adapters.ted_api import TedAPIAdapter, TedRequestAPI
1012
from ted_sws.notice_fetcher.services.notice_fetcher import NoticeFetcher
11-
from tests import TEST_DATA_PATH
1213

1314
NOTICE_STORAGE_FEATURES_TEST_DB = "features_test_db_for_notice"
1415

1516

1617
@pytest.fixture
17-
def api_end_point():
18+
def mongodb_end_point():
19+
return config.MONGO_DB_AUTH_URL
20+
21+
22+
@pytest.fixture(scope="function")
23+
@mongomock.patch(servers=(('server.example.com', 27017),))
24+
def mongodb_client():
25+
mongo_client = pymongo.MongoClient('server.example.com')
26+
for database_name in mongo_client.list_database_names():
27+
mongo_client.drop_database(database_name)
28+
return mongo_client
29+
30+
31+
@pytest.fixture
32+
def ted_api_end_point():
1833
return config.TED_API_URL
1934

2035

2136
@pytest.fixture
22-
def notice_storage():
23-
url = config.MONGO_DB_AUTH_URL
24-
mongodb_client = MongoClient(url)
25-
mongodb_client.drop_database(NOTICE_STORAGE_FEATURES_TEST_DB)
37+
def notice_repository(mongodb_client):
2638
return NoticeRepository(mongodb_client=mongodb_client, database_name=NOTICE_STORAGE_FEATURES_TEST_DB)
2739

2840

2941
@pytest.fixture
30-
def f03_notice_2020(notice_storage, api_end_point):
42+
def f03_notice_2020(notice_repository, ted_api_end_point):
3143
notice_search_query = {"q": "ND=[408313-2020]"}
32-
NoticeFetcher(notice_repository=notice_storage,
44+
NoticeFetcher(notice_repository=notice_repository,
3345
ted_api_adapter=TedAPIAdapter(request_api=TedRequestAPI(),
34-
ted_api_url=api_end_point)).fetch_notices_by_query(
46+
ted_api_url=ted_api_end_point)).fetch_notices_by_query(
3547
query=notice_search_query)
36-
notice = notice_storage.get(reference="408313-2020")
48+
notice = notice_repository.get(reference="408313-2020")
3749
notice.set_xml_metadata(xml_metadata=XMLMetadata(unique_xpaths=["FAKE_INDEX_XPATHS"]))
3850
return notice
3951

4052

4153
@pytest.fixture
42-
def f18_notice_2022(notice_storage, api_end_point):
54+
def f18_notice_2022(notice_repository, ted_api_end_point):
4355
notice_search_query = {"q": "ND=[067623-2022]"}
44-
NoticeFetcher(notice_repository=notice_storage,
56+
NoticeFetcher(notice_repository=notice_repository,
4557
ted_api_adapter=TedAPIAdapter(request_api=TedRequestAPI(),
46-
ted_api_url=api_end_point)).fetch_notices_by_query(
58+
ted_api_url=ted_api_end_point)).fetch_notices_by_query(
4759
query=notice_search_query)
48-
notice = notice_storage.get(reference="067623-2022")
60+
notice = notice_repository.get(reference="067623-2022")
4961
notice.set_xml_metadata(xml_metadata=XMLMetadata(unique_xpaths=["FAKE_INDEX_XPATHS"]))
5062
return notice
5163

5264

5365
@pytest.fixture
54-
def file_system_repository_path():
55-
return TEST_DATA_PATH / "notice_transformer" / "test_repository"
66+
def notice_id(notice_2020):
67+
return notice_2020.ted_id
5668

5769

5870
@pytest.fixture
59-
def mapping_suite_repository_in_file_system(file_system_repository_path):
60-
return MappingSuiteRepositoryInFileSystem(repository_path=file_system_repository_path)
71+
def fetched_notice_data(notice_2020):
72+
ted_id = notice_2020.ted_id
73+
original_metadata = notice_2020.original_metadata
74+
xml_manifestation = notice_2020.xml_manifestation
75+
return ted_id, original_metadata, xml_manifestation
76+
77+
78+
@pytest.fixture(scope="function")
79+
def publicly_available_notice(fetched_notice_data, normalised_metadata_dict) -> Notice:
80+
ted_id, original_metadata, xml_manifestation = fetched_notice_data
81+
sparql_validation = SPARQLTestSuiteValidationReport(object_data="This is validation report!",
82+
test_suite_identifier="sparql_test_id",
83+
mapping_suite_identifier="mapping_suite_id",
84+
validation_results=[])
85+
shacl_validation = SHACLTestSuiteValidationReport(object_data="This is validation report!",
86+
test_suite_identifier="shacl_test_id",
87+
mapping_suite_identifier="mapping_suite_id",
88+
validation_results=[])
89+
notice = Notice(ted_id=ted_id, original_metadata=original_metadata,
90+
xml_manifestation=xml_manifestation)
91+
notice._rdf_manifestation = RDFManifestation(object_data="RDF manifestation content",
92+
shacl_validations=[shacl_validation],
93+
sparql_validations=[sparql_validation]
94+
)
95+
notice._distilled_rdf_manifestation = RDFManifestation(object_data="RDF manifestation content",
96+
shacl_validations=[shacl_validation],
97+
sparql_validations=[sparql_validation]
98+
)
99+
notice._mets_manifestation = METSManifestation(object_data="METS manifestation content")
100+
notice._normalised_metadata = NormalisedMetadata(**normalised_metadata_dict)
101+
notice._preprocessed_xml_manifestation = xml_manifestation
102+
notice._status = NoticeStatus.PUBLICLY_AVAILABLE
103+
return notice

tests/features/model/__init__.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +0,0 @@
1-
#!/usr/bin/python3
2-
3-
# __init__.py
4-
# Date: 03/02/2022
5-
# Author: Eugeniu Costetchi
6-
# Email: costezki.eugen@gmail.com
7-
8-
""" """

tests/features/model/conftest.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,3 @@
1-
#!/usr/bin/python3
2-
3-
# conftest.py
4-
# Date: 29/01/2022
5-
# Author: Eugeniu Costetchi
6-
# Email: costezki.eugen@gmail.com
7-
8-
""" """
9-
101
import pytest
112

123
from ted_sws.core.model.manifestation import XMLManifestation, RDFManifestation, METSManifestation, \
@@ -64,3 +55,6 @@ def transformation_eligible_notice(indexed_notice, normalised_metadata_dict) ->
6455
indexed_notice.update_status_to(NoticeStatus.ELIGIBLE_FOR_TRANSFORMATION)
6556
indexed_notice.update_status_to(NoticeStatus.PREPROCESSED_FOR_TRANSFORMATION)
6657
return indexed_notice
58+
59+
60+

tests/features/model/test_notice_operations.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,17 @@
44
from ted_sws.core.model.manifestation import RDFManifestation, RDFValidationManifestation, METSManifestation
55
from ted_sws.core.model.metadata import NormalisedMetadata
66
from ted_sws.core.model.notice import NoticeStatus
7-
from tests.features import str2bool
7+
8+
9+
def str2bool(value: str) -> bool:
10+
"""
11+
Parse a string value and cast it into its boolean value
12+
:param value:
13+
:return:
14+
"""
15+
if value in ["y", "yes", "t", "true", "on", "1"]: return True
16+
if value in ["n", "no", "f", "false", "off", "0"]: return False
17+
raise ValueError("boolean value unrecognised")
818

919

1020
@scenario("test_notice_operations.feature", "add normalised metadata")
Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +0,0 @@
1-
#!/usr/bin/python3
2-
3-
# __init__.py
4-
# Date: 03/02/2022
5-
# Author: Eugeniu Costetchi
6-
# Email: costezki.eugen@gmail.com
7-
8-
""" """
Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,43 @@
1+
from datetime import date
2+
13
import pytest
24

5+
from ted_sws.notice_fetcher.adapters.ted_api import TedAPIAdapter, TedRequestAPI
6+
from ted_sws.notice_fetcher.services.notice_fetcher import NoticeFetcher
7+
from tests.fakes.fake_ted_api import FakeTedApiAdapter
8+
39

410
@pytest.fixture
5-
def notice_identifier():
11+
def fetch_notice_id():
612
return "067623-2022"
713

814

915
@pytest.fixture
10-
def notice_search_query():
11-
return {"q": "ND=[067623-2022]"}
16+
def fetch_start_date():
17+
return date(2020, 2, 3)
18+
19+
20+
@pytest.fixture
21+
def fetch_date(fetch_start_date):
22+
return fetch_start_date
23+
24+
25+
@pytest.fixture
26+
def fetch_end_date():
27+
return date(2020, 2, 3)
28+
29+
30+
@pytest.fixture
31+
def fetch_wildcard_date():
32+
return "20200203*"
1233

1334

1435
@pytest.fixture
15-
def notice_incorrect_search_query():
16-
return {"q": "ND=067623-20224856"}
36+
def fetch_query(fetch_wildcard_date):
37+
return {"q": f"PD=[{fetch_wildcard_date}]"}
1738

1839

40+
@pytest.fixture
41+
def notice_fetcher(notice_repository, ted_api_end_point):
42+
return NoticeFetcher(notice_repository=notice_repository,
43+
ted_api_adapter=FakeTedApiAdapter())

tests/features/notice_fetcher/test_notice_fetcher.feature

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,47 @@
1-
# Created by dude at 25/01/2022
1+
# Created by Stefan at 16.08.2022
22
Feature: Notice fetcher
33
The system is able to fetch selected TED-XML notices together with their metadata
44

5-
Scenario: Fetch a TED notice
6-
Given a TED REST API download endpoint
7-
And correct download API parameters
8-
When call to the API is made
9-
Then a notice and notice metadata is received from the API
10-
And the notice and notice metadata are stored
5+
Scenario: Fetch a notice by id, from Ted
6+
Given a notice_id
7+
And knowing the TED API endpoint
8+
And knowing database endpoint
9+
When notice fetching by id is executed
10+
Then fetched notice is available in database
11+
And fetched notice have raw status
12+
And fetched notice have xml_manifestation
13+
And fetched notice have original_metadata
1114

12-
Scenario: Fail to fetch a TED notice
13-
Given a TED REST API download endpoint
14-
And incorrect download API parameters
15-
When the call to the API is made
16-
And no notice or metadata is returned
17-
Then an error message is received indicating the problem
15+
Scenario: Fetch notices by query, from Ted
16+
Given a query
17+
And knowing the TED API endpoint
18+
And knowing database endpoint
19+
When notices fetching by query is executed
20+
Then a list of fetched notice_ids is returned
21+
And foreach returned notice_id exist in database a notice with RAW status
22+
And foreach returned notice_id exist in database a notice with xml_manifestation
23+
And foreach returned notice_id exist in database a notice with original_metadata
1824

25+
Scenario: Fetch notices by date range, from Ted
26+
Given a start_date
27+
And a end_date
28+
And knowing the TED API endpoint
29+
And knowing database endpoint
30+
When notices fetching by date range is executed
31+
Then a list of fetched notice_ids is returned
32+
And foreach returned notice_id exist in database a notice with RAW status
33+
And foreach returned notice_id exist in database a notice with xml_manifestation
34+
And foreach returned notice_id exist in database a notice with original_metadata
35+
36+
Scenario: Fetch notices by date wild card, from Ted
37+
Given a wildcard_date
38+
And knowing the TED API endpoint
39+
And knowing database endpoint
40+
When notices fetching by date wild card is executed
41+
Then a list of fetched notice_ids is returned
42+
And foreach returned notice_id exist in database a notice with RAW status
43+
And foreach returned notice_id exist in database a notice with xml_manifestation
44+
And foreach returned notice_id exist in database a notice with original_metadata
1945

2046

2147

0 commit comments

Comments
 (0)