Skip to content

Commit

Permalink
Merge branch 'no_libraries' into feature/SWS1-14
Browse files Browse the repository at this point in the history
  • Loading branch information
duprijil committed Jan 15, 2025
2 parents 50a8a45 + 17d8e24 commit f65ded1
Show file tree
Hide file tree
Showing 6 changed files with 57 additions and 1 deletion.
7 changes: 6 additions & 1 deletion .github/workflows/unit-tests-srv.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<cdm:work rdf:about="&resource;ted/{{ work.identifier }}">
{# <rdf:type rdf:resource="http://publications.europa.eu/ontology/cdm#work"/> #}
<rdf:type rdf:resource="http://publications.europa.eu/ontology/cdm#procurement_public"/>
<cdm:work_id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">{{ work.uri }}</cdm:work_id>
<cdm:work_id_document rdf:datatype="http://www.w3.org/2001/XMLSchema#string">ted:{{ work.identifier }}</cdm:work_id_document>
<cdm:work_id_document rdf:datatype="http://www.w3.org/2001/XMLSchema#string">oj:{{ work.oj_identifier }}</cdm:work_id_document>
<cdm:work_has_resource-type rdf:resource="http://publications.europa.eu/resource/authority/resource-type/PROCUREMENT_NOTICE"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<cdm:work rdf:about="&resource;ted/2021_S_004_003545">

<rdf:type rdf:resource="http://publications.europa.eu/ontology/cdm#procurement_public"/>
<cdm:work_id rdf:datatype="http://www.w3.org/2001/XMLSchema#string">http://data.europa.eu/a4g/resource/2021/003545_2021</cdm:work_id>
<cdm:work_id_document rdf:datatype="http://www.w3.org/2001/XMLSchema#string">ted:2021_S_004_003545</cdm:work_id_document>
<cdm:work_id_document rdf:datatype="http://www.w3.org/2001/XMLSchema#string">oj:JOS_2021_004_R_003545</cdm:work_id_document>
<cdm:work_has_resource-type rdf:resource="http://publications.europa.eu/resource/authority/resource-type/PROCUREMENT_NOTICE"/>
Expand Down
1 change: 1 addition & 0 deletions tests/unit/dags/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

6 changes: 6 additions & 0 deletions tests/unit/notice_packager/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
42 changes: 42 additions & 0 deletions tests/unit/notice_packager/test_template_generator.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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

0 comments on commit f65ded1

Please sign in to comment.