|
| 1 | +import mongomock |
| 2 | +import pymongo |
1 | 3 | import pytest |
2 | | -from pymongo import MongoClient |
3 | 4 |
|
4 | 5 | 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 |
7 | 10 | from ted_sws.data_manager.adapters.notice_repository import NoticeRepository |
8 | | - |
9 | 11 | from ted_sws.notice_fetcher.adapters.ted_api import TedAPIAdapter, TedRequestAPI |
10 | 12 | from ted_sws.notice_fetcher.services.notice_fetcher import NoticeFetcher |
11 | | -from tests import TEST_DATA_PATH |
12 | 13 |
|
13 | 14 | NOTICE_STORAGE_FEATURES_TEST_DB = "features_test_db_for_notice" |
14 | 15 |
|
15 | 16 |
|
16 | 17 | @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(): |
18 | 33 | return config.TED_API_URL |
19 | 34 |
|
20 | 35 |
|
21 | 36 | @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): |
26 | 38 | return NoticeRepository(mongodb_client=mongodb_client, database_name=NOTICE_STORAGE_FEATURES_TEST_DB) |
27 | 39 |
|
28 | 40 |
|
29 | 41 | @pytest.fixture |
30 | | -def f03_notice_2020(notice_storage, api_end_point): |
| 42 | +def f03_notice_2020(notice_repository, ted_api_end_point): |
31 | 43 | notice_search_query = {"q": "ND=[408313-2020]"} |
32 | | - NoticeFetcher(notice_repository=notice_storage, |
| 44 | + NoticeFetcher(notice_repository=notice_repository, |
33 | 45 | 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( |
35 | 47 | query=notice_search_query) |
36 | | - notice = notice_storage.get(reference="408313-2020") |
| 48 | + notice = notice_repository.get(reference="408313-2020") |
37 | 49 | notice.set_xml_metadata(xml_metadata=XMLMetadata(unique_xpaths=["FAKE_INDEX_XPATHS"])) |
38 | 50 | return notice |
39 | 51 |
|
40 | 52 |
|
41 | 53 | @pytest.fixture |
42 | | -def f18_notice_2022(notice_storage, api_end_point): |
| 54 | +def f18_notice_2022(notice_repository, ted_api_end_point): |
43 | 55 | notice_search_query = {"q": "ND=[067623-2022]"} |
44 | | - NoticeFetcher(notice_repository=notice_storage, |
| 56 | + NoticeFetcher(notice_repository=notice_repository, |
45 | 57 | 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( |
47 | 59 | query=notice_search_query) |
48 | | - notice = notice_storage.get(reference="067623-2022") |
| 60 | + notice = notice_repository.get(reference="067623-2022") |
49 | 61 | notice.set_xml_metadata(xml_metadata=XMLMetadata(unique_xpaths=["FAKE_INDEX_XPATHS"])) |
50 | 62 | return notice |
51 | 63 |
|
52 | 64 |
|
53 | 65 | @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 |
56 | 68 |
|
57 | 69 |
|
58 | 70 | @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 |
0 commit comments