diff --git a/.github/workflows/unit-tests-srv.yml b/.github/workflows/unit-tests-srv.yml index 617bd7bc4..48b951b01 100644 --- a/.github/workflows/unit-tests-srv.yml +++ b/.github/workflows/unit-tests-srv.yml @@ -51,11 +51,16 @@ jobs: env_vars: OS,PYTHON name: codecov-umbrella fail_ci_if_error: true + - name: Set working directory fir SonarCloud + run: mkdir -p $GITHUB_WORKSPACE/.scannerwork && chmod -R 777 $GITHUB_WORKSPACE/.scannerwork && pwd && ls -a + - name: SonarCloud Scan - uses: SonarSource/sonarcloud-github-action@master + uses: SonarSource/sonarqube-scan-action@v4.1.0 env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + with: + args: -Dsonar.working.directory=$GITHUB_WORKSPACE/.scannerwork # - name: Clean Mongo DB # run: make clean-mongo-db # - name: Upload coverage to Codecov diff --git a/ted_sws/notice_packager/resources/templates/mets_xml_dmd_rdf.jinja2 b/ted_sws/notice_packager/resources/templates/mets_xml_dmd_rdf.jinja2 index 775d14672..2fd521dfc 100644 --- a/ted_sws/notice_packager/resources/templates/mets_xml_dmd_rdf.jinja2 +++ b/ted_sws/notice_packager/resources/templates/mets_xml_dmd_rdf.jinja2 @@ -12,6 +12,7 @@ {# #} + {{ work.uri }} ted:{{ work.identifier }} oj:{{ work.oj_identifier }} diff --git a/tests/test_data/notice_packager/templates/2021_S_004_003545_0.mets.xml.dmd.rdf b/tests/test_data/notice_packager/templates/2021_S_004_003545_0.mets.xml.dmd.rdf index 7a4226f3e..28562c5f2 100644 --- a/tests/test_data/notice_packager/templates/2021_S_004_003545_0.mets.xml.dmd.rdf +++ b/tests/test_data/notice_packager/templates/2021_S_004_003545_0.mets.xml.dmd.rdf @@ -12,6 +12,7 @@ + http://data.europa.eu/a4g/resource/2021/003545_2021 ted:2021_S_004_003545 oj:JOS_2021_004_R_003545 diff --git a/tests/unit/dags/__init__.py b/tests/unit/dags/__init__.py index 1a2507f72..1e677c661 100644 --- a/tests/unit/dags/__init__.py +++ b/tests/unit/dags/__init__.py @@ -40,3 +40,4 @@ FULL_BRANCH_TASK_IDS = [START_PROCESSING_NOTICE_TASK_ID, INDEX_NOTICE_XML_CONTENT_TASK_ID, NORMALISE_NOTICE_METADATA_TASK_ID] + TRANSFORM_BRANCH_TASK_IDS + PACKAGE_BRANCH_TASK_IDS + PUBLISH_BRANCH_TASK_IDS + diff --git a/tests/unit/notice_packager/conftest.py b/tests/unit/notice_packager/conftest.py index 6ad49bb87..fb3a29f56 100644 --- a/tests/unit/notice_packager/conftest.py +++ b/tests/unit/notice_packager/conftest.py @@ -98,3 +98,9 @@ def invalid_rdf_files_path(): @pytest.fixture def notice_id(): return "196390_2018" + + +@pytest.fixture +def work_id_predicate(): + """Returns the URI predicate for the CDM work identifier.""" + return "http://publications.europa.eu/ontology/cdm#work_id" \ No newline at end of file diff --git a/tests/unit/notice_packager/test_template_generator.py b/tests/unit/notice_packager/test_template_generator.py index 330b63fd4..ad1456ded 100644 --- a/tests/unit/notice_packager/test_template_generator.py +++ b/tests/unit/notice_packager/test_template_generator.py @@ -9,8 +9,10 @@ import re import pytest +from rdflib import Graph, Literal, XSD from ted_sws.notice_packager.adapters.template_generator import TemplateGenerator +from ted_sws.notice_packager.model.metadata import PackagerMetadata from tests import TEST_DATA_PATH @@ -57,3 +59,43 @@ def test_mets2action_mets_xml_generator_with_wrong_action(template_sample_metada template_sample_metadata.mets.type = "wrong_action" with pytest.raises(ValueError): TemplateGenerator.mets2action_mets_xml_generator(template_sample_metadata) + + +def test_mets_dmd_rdf_has_work_id_after_generation(template_sample_metadata: PackagerMetadata, + work_id_predicate: str): + """Test that generated METS DMD RDF contains a work_id predicate.""" + mets_dmd_rdf: str = TemplateGenerator.mets_xml_dmd_rdf_generator(template_sample_metadata) + mets_graph: Graph = Graph().parse(data=mets_dmd_rdf, format="xml") + + work_id_predicate_exists: bool = mets_graph.query( + f""" ASK WHERE {{ ?subject <{work_id_predicate}> ?object . }} """).askAnswer + + assert work_id_predicate_exists + + +def test_mets_dmd_rdf_has_work_id_as_string_after_generation(template_sample_metadata: PackagerMetadata, + work_id_predicate: str): + """Test that work_id in METS DMD RDF is of type xsd:string.""" + mets_dmd_rdf: str = TemplateGenerator.mets_xml_dmd_rdf_generator(template_sample_metadata) + mets_graph: Graph = Graph().parse(data=mets_dmd_rdf, format="xml") + string_datatype = XSD.string + + work_id_predicate_exists: bool = mets_graph.query( + f""" ASK WHERE {{ ?subject <{work_id_predicate}> ?object . FILTER(datatype(?object) = <{string_datatype}>) }} """).askAnswer + + assert work_id_predicate_exists + + +def test_mets_dmd_rdf_has_correct_work_id_value_after_generation(template_sample_metadata: PackagerMetadata, + work_id_predicate: str): + """Test that work_id value in METS DMD RDF matches the metadata work URI.""" + mets_dmd_rdf: str = TemplateGenerator.mets_xml_dmd_rdf_generator(template_sample_metadata) + mets_graph: Graph = Graph().parse(data=mets_dmd_rdf, format="xml") + + assert template_sample_metadata.work.uri + work_id_value_literal = Literal(template_sample_metadata.work.uri, datatype=XSD.string) + + work_id_is_same: bool = mets_graph.query( + f""" ASK WHERE {{ ?subject <{work_id_predicate}> {work_id_value_literal.n3()} . }} """).askAnswer + + assert work_id_is_same