Skip to content

Commit 575ec35

Browse files
committed
Merge branch 'no_libraries' into feature/SWS1-12
2 parents 2adcdbd + 17d8e24 commit 575ec35

6 files changed

Lines changed: 55 additions & 1 deletion

File tree

.github/workflows/unit-tests-srv.yml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,16 @@ jobs:
5151
env_vars: OS,PYTHON
5252
name: codecov-umbrella
5353
fail_ci_if_error: true
54+
- name: Set working directory fir SonarCloud
55+
run: mkdir -p $GITHUB_WORKSPACE/.scannerwork && chmod -R 777 $GITHUB_WORKSPACE/.scannerwork && pwd && ls -a
56+
5457
- name: SonarCloud Scan
55-
uses: SonarSource/sonarcloud-github-action@master
58+
uses: SonarSource/sonarqube-scan-action@v4.1.0
5659
env:
5760
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
5861
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
62+
with:
63+
args: -Dsonar.working.directory=$GITHUB_WORKSPACE/.scannerwork
5964
# - name: Clean Mongo DB
6065
# run: make clean-mongo-db
6166
# - name: Upload coverage to Codecov

ted_sws/notice_packager/resources/templates/mets_xml_dmd_rdf.jinja2

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<cdm:work rdf:about="&resource;ted/{{ work.identifier }}">
1313
{# <rdf:type rdf:resource="http://publications.europa.eu/ontology/cdm#work"/> #}
1414
<rdf:type rdf:resource="http://publications.europa.eu/ontology/cdm#procurement_public"/>
15+
<cdm:work_id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">{{ work.uri }}</cdm:work_id>
1516
<cdm:work_id_document rdf:datatype="http://www.w3.org/2001/XMLSchema#string">ted:{{ work.identifier }}</cdm:work_id_document>
1617
<cdm:work_id_document rdf:datatype="http://www.w3.org/2001/XMLSchema#string">oj:{{ work.oj_identifier }}</cdm:work_id_document>
1718
<cdm:work_has_resource-type rdf:resource="http://publications.europa.eu/resource/authority/resource-type/PROCUREMENT_NOTICE"/>

tests/test_data/notice_packager/templates/2021_S_004_003545_0.mets.xml.dmd.rdf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<cdm:work rdf:about="&resource;ted/2021_S_004_003545">
1313

1414
<rdf:type rdf:resource="http://publications.europa.eu/ontology/cdm#procurement_public"/>
15+
<cdm:work_id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">http://data.europa.eu/a4g/resource/2021/003545_2021</cdm:work_id>
1516
<cdm:work_id_document rdf:datatype="http://www.w3.org/2001/XMLSchema#string">ted:2021_S_004_003545</cdm:work_id_document>
1617
<cdm:work_id_document rdf:datatype="http://www.w3.org/2001/XMLSchema#string">oj:JOS_2021_004_R_003545</cdm:work_id_document>
1718
<cdm:work_has_resource-type rdf:resource="http://publications.europa.eu/resource/authority/resource-type/PROCUREMENT_NOTICE"/>

tests/unit/dags/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,4 @@
4040

4141
FULL_BRANCH_TASK_IDS = [START_PROCESSING_NOTICE_TASK_ID, INDEX_NOTICE_XML_CONTENT_TASK_ID,
4242
NORMALISE_NOTICE_METADATA_TASK_ID] + TRANSFORM_BRANCH_TASK_IDS + PACKAGE_BRANCH_TASK_IDS + PUBLISH_BRANCH_TASK_IDS
43+

tests/unit/notice_packager/conftest.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,3 +115,9 @@ def invalid_rdf_files_path():
115115
@pytest.fixture
116116
def notice_id():
117117
return "196390_2018"
118+
119+
120+
@pytest.fixture
121+
def work_id_predicate():
122+
"""Returns the URI predicate for the CDM work identifier."""
123+
return "http://publications.europa.eu/ontology/cdm#work_id"

tests/unit/notice_packager/test_template_generator.py

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from xml.etree.ElementTree import ParseError
1212

1313
import pytest
14+
from rdflib import Graph, Literal, XSD
1415

1516
from ted_sws.notice_packager.adapters.template_generator import TemplateGenerator
1617
from ted_sws.notice_packager.model.metadata import PackagerMetadata
@@ -72,3 +73,42 @@ def test_mets2action_mets_xml_generator_with_wrong_action(template_sample_metada
7273
#
7374
# # Parse to check if xml is well-formed (HTML-safe sequences or elements)
7475
# ElementTree.fromstring(mets_dmd_rdf)
76+
77+
def test_mets_dmd_rdf_has_work_id_after_generation(template_sample_metadata: PackagerMetadata,
78+
work_id_predicate: str):
79+
"""Test that generated METS DMD RDF contains a work_id predicate."""
80+
mets_dmd_rdf: str = TemplateGenerator.mets_xml_dmd_rdf_generator(template_sample_metadata)
81+
mets_graph: Graph = Graph().parse(data=mets_dmd_rdf, format="xml")
82+
83+
work_id_predicate_exists: bool = mets_graph.query(
84+
f""" ASK WHERE {{ ?subject <{work_id_predicate}> ?object . }} """).askAnswer
85+
86+
assert work_id_predicate_exists
87+
88+
89+
def test_mets_dmd_rdf_has_work_id_as_string_after_generation(template_sample_metadata: PackagerMetadata,
90+
work_id_predicate: str):
91+
"""Test that work_id in METS DMD RDF is of type xsd:string."""
92+
mets_dmd_rdf: str = TemplateGenerator.mets_xml_dmd_rdf_generator(template_sample_metadata)
93+
mets_graph: Graph = Graph().parse(data=mets_dmd_rdf, format="xml")
94+
string_datatype = XSD.string
95+
96+
work_id_predicate_exists: bool = mets_graph.query(
97+
f""" ASK WHERE {{ ?subject <{work_id_predicate}> ?object . FILTER(datatype(?object) = <{string_datatype}>) }} """).askAnswer
98+
99+
assert work_id_predicate_exists
100+
101+
102+
def test_mets_dmd_rdf_has_correct_work_id_value_after_generation(template_sample_metadata: PackagerMetadata,
103+
work_id_predicate: str):
104+
"""Test that work_id value in METS DMD RDF matches the metadata work URI."""
105+
mets_dmd_rdf: str = TemplateGenerator.mets_xml_dmd_rdf_generator(template_sample_metadata)
106+
mets_graph: Graph = Graph().parse(data=mets_dmd_rdf, format="xml")
107+
108+
assert template_sample_metadata.work.uri
109+
work_id_value_literal = Literal(template_sample_metadata.work.uri, datatype=XSD.string)
110+
111+
work_id_is_same: bool = mets_graph.query(
112+
f""" ASK WHERE {{ ?subject <{work_id_predicate}> {work_id_value_literal.n3()} . }} """).askAnswer
113+
114+
assert work_id_is_same

0 commit comments

Comments
 (0)