Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue #550 #561

Merged
merged 8 commits into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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

5 changes: 5 additions & 0 deletions tests/unit/notice_packager/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,8 @@ def invalid_rdf_files_path():
@pytest.fixture
def notice_id():
return "196390_2018"


@pytest.fixture
def work_id_predicate():
return "http://publications.europa.eu/ontology/cdm#work_id"
39 changes: 39 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,40 @@ 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):
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):
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):
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


Loading