Skip to content

Commit

Permalink
fix paths
Browse files Browse the repository at this point in the history
  • Loading branch information
anastasianayden committed Jan 4, 2024
1 parent 0d7ab6e commit 3be98ce
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
1 change: 0 additions & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,5 @@ jobs:
ckan -c test.ini db init
- name: Run tests
working-directory: ckanext-fairdatapoint
run: pytest --ckan-ini=test.ini --cov=ckanext.fairdatapoint --disable-warnings ckanext/fairdatapoint

15 changes: 7 additions & 8 deletions ckanext/fairdatapoint/tests/test_processors.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
import pytest
from pathlib import Path
from unittest.mock import patch
from rdflib import Graph
from ckanext.fairdatapoint.harvesters.domain.fair_data_point_record_to_package_converter import (
FairDataPointRecordToPackageConverter)

TEST_DATA_DIRECTORY = Path(Path(__file__).parent.resolve(), "test_data")


@pytest.mark.ckan_config("ckan.plugins", "scheming_datasets")
@pytest.mark.usefixtures("with_plugins")
class TestProcessors:
@patch("ckanext.fairdatapoint.processors.FairDataPointRDFParser.datasets")
def test_fdp_record_converter_dataset(self, parser_datasets):
fdp_record_to_package = FairDataPointRecordToPackageConverter(profile="fairdatapoint_dcat_ap")
data = Graph().parse("./ckanext-fairdatapoint/ckanext/fairdatapoint/tests/test_data/"
"Project_27866022694497978_out.ttl").serialize()
data = Graph().parse(Path(TEST_DATA_DIRECTORY, "Project_27866022694497978_out.ttl")).serialize()
fdp_record_to_package.record_to_package(guid="catalog=https://covid19initiatives.health-ri.nl/p/"
"ProjectOverview?focusarea=http://purl.org/zonmw/generic/10006;"
"dataset=https://covid19initiatives.health-ri.nl/p/Project/"
Expand All @@ -23,17 +25,15 @@ def test_fdp_record_converter_dataset(self, parser_datasets):
@patch("ckanext.fairdatapoint.processors.FairDataPointRDFParser.catalogs")
def test_fdp_record_converter_catalog(self, parser_catalogs):
fdp_record_to_package = FairDataPointRecordToPackageConverter(profile="fairdatapoint_dcat_ap")
data = Graph().parse(
"./ckanext-fairdatapoint/ckanext/fairdatapoint/tests/test_data/fdp_catalog.ttl").serialize()
data = Graph().parse(Path(TEST_DATA_DIRECTORY, "fdp_catalog.ttl")).serialize()
fdp_record_to_package.record_to_package(
guid="catalog=https://fair.healthinformationportal.eu/catalog/1c75c2c9-d2cc-44cb-aaa8-cf8c11515c8d",
record=data)
assert parser_catalogs.called

def test_fdp_record_converter_dataset_dict(self):
fdp_record_to_package = FairDataPointRecordToPackageConverter(profile="fairdatapoint_dcat_ap")
data = Graph().parse("./ckanext-fairdatapoint/ckanext/fairdatapoint/tests/test_data/"
"Project_27866022694497978_out.ttl").serialize()
data = Graph().parse(Path(TEST_DATA_DIRECTORY, "Project_27866022694497978_out.ttl")).serialize()
actual_dataset = fdp_record_to_package.record_to_package(
guid="catalog=https://covid19initiatives.health-ri.nl/p/ProjectOverview?focusarea="
"http://purl.org/zonmw/generic/10006;"
Expand Down Expand Up @@ -61,8 +61,7 @@ def test_fdp_record_converter_dataset_dict(self):

def test_fdp_record_converter_catalog_dict(self):
fdp_record_to_package = FairDataPointRecordToPackageConverter(profile="fairdatapoint_dcat_ap")
data = Graph().parse(
"./ckanext-fairdatapoint/ckanext/fairdatapoint/tests/test_data/fdp_catalog.ttl").serialize()
data = Graph().parse(Path(TEST_DATA_DIRECTORY, "fdp_catalog.ttl")).serialize()
actual = fdp_record_to_package.record_to_package(
guid="catalog=https://fair.healthinformationportal.eu/catalog/1c75c2c9-d2cc-44cb-aaa8-cf8c11515c8d",
record=data)
Expand Down
19 changes: 10 additions & 9 deletions ckanext/fairdatapoint/tests/test_record_provider.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import pytest
import requests_mock
from pathlib import Path
from pytest_mock import class_mocker, mocker
from rdflib import Graph, URIRef
from ckanext.fairdatapoint.harvesters.domain.fair_data_point_record_provider import FairDataPointRecordProvider

TEST_DATA_DIRECTORY = Path(Path(__file__).parent.resolve(), "test_data")

TEST_CAT_IDS_DICT = {
"catalog=https://fair.healthinformationportal.eu/catalog/1c75c2c9-d2cc-44cb-aaa8-cf8c11515c8d":
Expand All @@ -24,7 +26,7 @@
def get_graph_by_id(*args, **kwargs):
file_id = args[0]
file_id = "_".join(file_id.split("/")[-2:])
path_to_file = f"./ckanext-fairdatapoint/ckanext/fairdatapoint/tests/test_data/{file_id}.ttl"
path_to_file = Path(TEST_DATA_DIRECTORY, f"{file_id}.ttl")
graph = Graph().parse(path_to_file)
return graph

Expand All @@ -34,9 +36,9 @@ class TestRecordProvider:

@pytest.mark.parametrize("fdp_response_file,expected",
[
("./ckanext/fairdatapoint/tests/test_data/root_fdp_response.ttl",
(Path(TEST_DATA_DIRECTORY, "root_fdp_response.ttl"),
TEST_CAT_IDS_DICT.keys()),
("./ckanext/fairdatapoint/tests/test_data/root_fdp_response_no_catalogs.ttl",
(Path(TEST_DATA_DIRECTORY, "root_fdp_response_no_catalogs.ttl"),
dict().keys())
])
def test_get_record_ids(self, mocker, fdp_response_file, expected):
Expand Down Expand Up @@ -66,8 +68,8 @@ def test_get_record_by_id(self, mocker):
"dataset=https://fair.healthinformationportal.eu/dataset/898ca4b8-197b-4d40-bc81-d9cd88197670")
fdp_get_graph.side_effect = get_graph_by_id
actual = self.fdp_record_provider.get_record_by_id(guid)
expected = Graph().parse(f"./ckanext-fairdatapoint/ckanext/fairdatapoint/tests/test_data/"
f"dataset_898ca4b8-197b-4d40-bc81-d9cd88197670.ttl").serialize()
expected = Graph().parse(
Path(TEST_DATA_DIRECTORY, "dataset_898ca4b8-197b-4d40-bc81-d9cd88197670.ttl")).serialize()
assert actual == expected

def test_get_record_by_id_distr(self, mocker):
Expand All @@ -79,8 +81,8 @@ def test_get_record_by_id_distr(self, mocker):
"dataset=https://health-ri.sandbox.semlab-leiden.nl/dataset/d7129d28-b72a-437f-8db0-4f0258dd3c25")
fdp_get_graph.side_effect = get_graph_by_id
actual = self.fdp_record_provider.get_record_by_id(guid)
expected = Graph().parse("./ckanext-fairdatapoint/ckanext/fairdatapoint/tests/test_data/"
"dataset_d7129d28-b72a-437f-8db0-4f0258dd3c25_out.ttl").serialize()
expected = Graph().parse(
Path(TEST_DATA_DIRECTORY, "dataset_d7129d28-b72a-437f-8db0-4f0258dd3c25_out.ttl")).serialize()
assert actual == expected

def test_orcid_call(self, mocker):
Expand All @@ -96,7 +98,6 @@ def test_orcid_call(self, mocker):
"dataset=https://covid19initiatives.health-ri.nl/p/Project/27866022694497978")
fdp_get_graph.side_effect = get_graph_by_id
actual = self.fdp_record_provider.get_record_by_id(guid)
expected = Graph().parse("./ckanext-fairdatapoint/ckanext/fairdatapoint/tests/test_data/"
"Project_27866022694497978_out.ttl").serialize()
expected = Graph().parse(Path(TEST_DATA_DIRECTORY, "Project_27866022694497978_out.ttl")).serialize()
assert mock.called
assert actual == expected

0 comments on commit 3be98ce

Please sign in to comment.