Skip to content

Commit 2155732

Browse files
author
Kolea Plesco
committed
merge with main
2 parents 47e5eea + f6bfa33 commit 2155732

9 files changed

Lines changed: 576 additions & 95 deletions

File tree

dags/old_worker_single_notice_process_orchestrator.py

Lines changed: 476 additions & 0 deletions
Large diffs are not rendered by default.

dags/worker_single_notice_process_orchestrator.py

Lines changed: 57 additions & 80 deletions
Large diffs are not rendered by default.

infra/airflow/docker-compose.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ x-airflow-common:
5757
AIRFLOW__CELERY__BROKER_URL: redis://:@redis:6379/0
5858
AIRFLOW__CORE__FERNET_KEY: ''
5959
AIRFLOW__CORE__DAGS_ARE_PAUSED_AT_CREATION: 'true'
60+
AIRFLOW__CORE__ENABLE_XCOM_PICKLING: "true"
6061
AIRFLOW__CORE__LOAD_EXAMPLES: 'false'
6162
AIRFLOW__API__AUTH_BACKEND: 'airflow.api.auth.backend.basic_auth'
6263
_PIP_ADDITIONAL_REQUIREMENTS: ${_PIP_ADDITIONAL_REQUIREMENTS:-}

ted_sws/core/model/manifestation.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,9 @@ def add_validation(self, validation: Union[XPATHCoverageValidationReport]):
9999
self.xpath_coverage_validation: XPATHCoverageValidationReport = validation
100100

101101
def is_validated(self) -> bool:
102+
print("K :: ", self.xpath_coverage_validation)
102103
if self.xpath_coverage_validation:
104+
print("K :: VALIDATED")
103105
return True
104106
return False
105107

ted_sws/mapping_suite_processor/adapters/github_package_downloader.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
import subprocess
55
import tempfile
66

7-
GITHUB_TED_SWS_ARTEFACTS_REPOSITORY_NAME = "ted-sws-artefacts"
8-
GITHUB_TED_SWS_ARTEFACTS_MAPPINGS_PATH = "ted-sws-artefacts/mappings"
7+
GITHUB_TED_SWS_ARTEFACTS_REPOSITORY_NAME = "ted-rdf-mapping"
8+
GITHUB_TED_SWS_ARTEFACTS_MAPPINGS_PATH = f"{GITHUB_TED_SWS_ARTEFACTS_REPOSITORY_NAME}/mappings"
99

1010

1111
class MappingSuitePackageDownloaderABC(abc.ABC):
@@ -48,6 +48,7 @@ def get_git_head_hash(git_repository_path: pathlib.Path) -> str:
4848
This function return hash for last commit with git.
4949
:return:
5050
"""
51+
git_repository_path.mkdir(exist_ok=True, parents=True)
5152
result = subprocess.run(f'cd {git_repository_path} && git rev-parse origin/main', shell=True,
5253
stdout=subprocess.PIPE)
5354
git_head_hash = result.stdout.decode(encoding="utf-8")

ted_sws/notice_validator/services/xpath_coverage_runner.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from ted_sws.data_manager.adapters.notice_repository import NoticeRepository
77
from ted_sws.data_manager.adapters.repository_abc import MappingSuiteRepositoryABC
88
from ted_sws.notice_validator.adapters.xpath_coverage_runner import CoverageRunner, PATH_TYPE
9+
from pymongo import MongoClient
910

1011

1112
class XPATHCoverageReportBuilder:
@@ -25,9 +26,8 @@ def generate_report(self) -> XPATHCoverageValidationReport:
2526
def coverage_notice_xpath_report(notices: List[Notice], mapping_suite_id,
2627
conceptual_mappings_file_path: PATH_TYPE = None,
2728
coverage_runner: CoverageRunner = None, xslt_transformer=None,
28-
notice_repository: NoticeRepository = None) -> XPATHCoverageValidationReport:
29+
mongodb_client: MongoClient = None) -> XPATHCoverageValidationReport:
2930
if not coverage_runner:
30-
mongodb_client = notice_repository.mongodb_client if notice_repository else None
3131
coverage_runner = CoverageRunner(mapping_suite_id, conceptual_mappings_file_path, xslt_transformer,
3232
mongodb_client)
3333
report: XPATHCoverageValidationReport = coverage_runner.coverage_notice_xpath(notices, mapping_suite_id)
@@ -42,23 +42,24 @@ def xpath_coverage_html_report(report: XPATHCoverageValidationReport) -> str:
4242
return CoverageRunner.html_report(report)
4343

4444

45-
def validate_xpath_coverage_notice(notice: Notice, mapping_suite: MappingSuite, notice_repository: NoticeRepository):
45+
def validate_xpath_coverage_notice(notice: Notice, mapping_suite: MappingSuite, mongodb_client: MongoClient):
4646
xpath_coverage_report = coverage_notice_xpath_report(notices=[notice],
4747
mapping_suite_id=mapping_suite.identifier,
48-
notice_repository=notice_repository)
48+
mongodb_client=mongodb_client)
4949
report_builder = XPATHCoverageReportBuilder(xpath_coverage_report=xpath_coverage_report)
5050
notice.set_xml_validation(xml_validation=report_builder.generate_report())
5151

5252

5353
def validate_xpath_coverage_notice_by_id(notice_id: str, mapping_suite_identifier: str,
5454
mapping_suite_repository: MappingSuiteRepositoryABC,
55-
notice_repository: NoticeRepository):
55+
mongodb_client: MongoClient):
56+
notice_repository = NoticeRepository(mongodb_client=mongodb_client)
5657
notice = notice_repository.get(reference=notice_id)
5758
if notice is None:
5859
raise ValueError(f'Notice, with {notice_id} id, was not found')
5960

6061
mapping_suite = mapping_suite_repository.get(reference=mapping_suite_identifier)
6162
if mapping_suite is None:
6263
raise ValueError(f'Mapping suite, with {mapping_suite_identifier} id, was not found')
63-
validate_xpath_coverage_notice(notice=notice, mapping_suite=mapping_suite, notice_repository=notice_repository)
64+
validate_xpath_coverage_notice(notice=notice, mapping_suite=mapping_suite, mongodb_client=mongodb_client)
6465
notice_repository.update(notice=notice)
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/python3
2+
3+
# test_notice_transmisions.py
4+
# Date: 08.08.2022
5+
# Author: Stratulat Ștefan
6+
# Email: stefan.stratulat1997@gmail.com
7+
import pickle
8+
9+
from ted_sws.data_manager.adapters.notice_repository import NoticeRepository
10+
from deepdiff import DeepDiff
11+
12+
13+
def test_notice_is_convertible_to_dict(notice_2021):
14+
notice = notice_2021
15+
notice_dict = NoticeRepository._create_dict_from_notice(notice)
16+
result_notice = NoticeRepository._create_notice_from_repository_result(notice_dict)
17+
assert DeepDiff(notice.dict(), result_notice.dict(), ignore_order=True) == {}
18+
19+
20+
def test_notice_is_convertible_to_pickle(notice_2021):
21+
notice = notice_2021
22+
notice_dump = pickle.dumps(notice)
23+
result_notice = pickle.loads(notice_dump)
24+
assert DeepDiff(notice.dict(), result_notice.dict(), ignore_order=True) == {}

tests/e2e/dags/test_worker_dag_steps.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
CHECK_NOTICE_STATE_BEFORE_TRANSFORM_TASK_ID, CHECK_NOTICE_STATE_BEFORE_GENERATE_METS_PACKAGE_TASK_ID, \
1111
INDEX_NOTICE_XML_CONTENT_TASK_ID
1212

13-
DAG_ID = "worker_single_notice_process_orchestrator"
13+
DAG_ID = "old_worker_single_notice_process_orchestrator"
1414

1515

1616
def execute_dag_step(dag, task_id: str, dag_config: dict, xcom_push_data: dict = None):

tests/unit/notice_validator/test_xpath_coverage_runner.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
def test_xpath_coverage_runner(fake_notice_F03, fake_conceptual_mappings_F03_path, fake_xslt_transformer,
1313
fake_mapping_suite_F03_id, mongodb_client, fake_mapping_suite_F03_path,
1414
invalid_mapping_suite_id):
15-
notice_repository = NoticeRepository(mongodb_client=mongodb_client)
1615
report = coverage_notice_xpath_report([fake_notice_F03], fake_mapping_suite_F03_id,
1716
fake_conceptual_mappings_F03_path, None, fake_xslt_transformer)
1817
json_report = xpath_coverage_json_report(report)
@@ -31,14 +30,14 @@ def test_xpath_coverage_runner(fake_notice_F03, fake_conceptual_mappings_F03_pat
3130

3231
report = coverage_notice_xpath_report([fake_notice_F03], fake_mapping_suite_F03_id,
3332
fake_conceptual_mappings_F03_path, None, fake_xslt_transformer,
34-
notice_repository)
33+
mongodb_client)
3534
json_report = xpath_coverage_json_report(report)
3635
assert isinstance(json_report, dict)
3736

3837
with pytest.raises(ValueError):
3938
coverage_notice_xpath_report([fake_notice_F03], invalid_mapping_suite_id,
4039
None, None, fake_xslt_transformer,
41-
notice_repository)
40+
mongodb_client)
4241

4342

4443
def test_validate_xpath_coverage_notice_by_id(fake_notice_id, fake_mapping_suite_F03_id,
@@ -54,7 +53,7 @@ def test_validate_xpath_coverage_notice_by_id(fake_notice_id, fake_mapping_suite
5453
notice_id=fake_notice_id,
5554
mapping_suite_identifier=fake_mapping_suite_F03_id,
5655
mapping_suite_repository=mapping_suite_repository_db,
57-
notice_repository=notice_repository)
56+
mongodb_client=mongodb_client)
5857

5958
notice_repository.add(fake_notice_F03)
6059

@@ -63,12 +62,12 @@ def test_validate_xpath_coverage_notice_by_id(fake_notice_id, fake_mapping_suite
6362
notice_id=fake_notice_id,
6463
mapping_suite_identifier=fake_mapping_suite_F03_id,
6564
mapping_suite_repository=mapping_suite_repository_db,
66-
notice_repository=notice_repository)
65+
mongodb_client=mongodb_client)
6766

6867
mapping_suite_repository_db.add(mapping_suite)
6968

7069
validate_xpath_coverage_notice_by_id(
7170
notice_id=fake_notice_id,
7271
mapping_suite_identifier=fake_mapping_suite_F03_id,
7372
mapping_suite_repository=mapping_suite_repository_db,
74-
notice_repository=notice_repository)
73+
mongodb_client=mongodb_client)

0 commit comments

Comments
 (0)