コード例 #1
0
def test_to_graph_should_return_access_rights_comment() -> None:
    """It returns a access rights comment graph isomorphic to spec."""
    dataset = Dataset()
    dataset.identifier = "http://example.com/datasets/1"
    dataset.access_rights_comments.append("http://example.com/concepts/1")

    src = """
    @prefix dct: <http://purl.org/dc/terms/> .
    @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
    @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
    @prefix dcat: <http://www.w3.org/ns/dcat#> .
    @prefix xsd:   <http://www.w3.org/2001/XMLSchema#> .
    @prefix dcatno: <https://data.norge.no/vocabulary/dcatno#> .

    <http://example.com/datasets/1> a dcat:Dataset ;
            dcatno:accessRightsComment <http://example.com/concepts/1> ;
    .
    """
    g1 = Graph().parse(data=dataset.to_rdf(), format="turtle")
    g2 = Graph().parse(data=src, format="turtle")

    _isomorphic = isomorphic(g1, g2)
    if not _isomorphic:
        _dump_diff(g1, g2)
        pass
    assert _isomorphic
コード例 #2
0
def test_to_graph_should_return_relation_as_graph() -> None:
    """It returns a title graph isomorphic to spec."""
    relationship = Relationship()
    relationship.identifier = "http://example.com/relationships/1"
    relationship.had_role = "http://www.iana.org/assignments/relation/original"
    dataset = Dataset()
    dataset.identifier = "http://example.com/datasets/1"
    relationship.relation = dataset

    src = """
    @prefix dct: <http://purl.org/dc/terms/> .
    @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
    @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
    @prefix dcat: <http://www.w3.org/ns/dcat#> .

    <http://example.com/relationships/1> a dcat:Relationship ;
        dct:relation   <http://example.com/datasets/1> ;
        dcat:hadRole <http://www.iana.org/assignments/relation/original>
    .
    """
    g1 = Graph().parse(data=relationship.to_rdf(), format="turtle")
    g2 = Graph().parse(data=src, format="turtle")

    _isomorphic = isomorphic(g1, g2)
    if not _isomorphic:
        _dump_diff(g1, g2)
        pass
    assert _isomorphic
コード例 #3
0
def test_to_graph_should_return_modification_date() -> None:
    """It returns a modified graph isomorphic to spec."""
    resource = Dataset()
    resource.identifier = "http://example.com/datasets/1"
    resource.modification_date = "2020-03-24"

    src = """
    @prefix dct: <http://purl.org/dc/terms/> .
    @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
    @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
    @prefix dcat: <http://www.w3.org/ns/dcat#> .
    @prefix xsd:   <http://www.w3.org/2001/XMLSchema#> .

    <http://example.com/datasets/1> a dcat:Dataset ;
        dct:modified   "2020-03-24"^^xsd:date ;
        .
    """
    g1 = Graph().parse(data=resource.to_rdf(), format="turtle")
    g2 = Graph().parse(data=src, format="turtle")

    _isomorphic = isomorphic(g1, g2)
    if not _isomorphic:
        _dump_diff(g1, g2)
        pass
    assert _isomorphic
コード例 #4
0
def test_to_graph_should_return_theme() -> None:
    """It returns a theme graph isomorphic to spec."""
    resource = Dataset()
    resource.identifier = "http://example.com/datasets/1"
    resource.theme.append("http://example.com/themes/1")
    resource.theme.append("http://example.com/themes/2")

    src = """
    @prefix dct: <http://purl.org/dc/terms/> .
    @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
    @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
    @prefix dcat: <http://www.w3.org/ns/dcat#> .

    <http://example.com/datasets/1> a dcat:Dataset ;
        dcat:theme   <http://example.com/themes/1> ,
                     <http://example.com/themes/2> ;
        .
    """
    g1 = Graph().parse(data=resource.to_rdf(), format="turtle")
    g2 = Graph().parse(data=src, format="turtle")

    _isomorphic = isomorphic(g1, g2)
    if not _isomorphic:
        _dump_diff(g1, g2)
        pass
    assert _isomorphic
コード例 #5
0
def test_to_graph_should_return_qualified_attributions() -> None:
    """It returns a qualified_attributions graph isomorphic to spec."""
    resource = Dataset()
    resource.identifier = "http://example.com/datasets/1"
    qualified_attribution = {}
    qualified_attribution["agent"] = "http://example.com/agents/1"
    qualified_attribution[
        "hadrole"
    ] = "http://registry.it.csiro.au/def/isotc211/CI_RoleCode/distributor"
    resource.qualified_attributions.append(qualified_attribution)

    src = """
    @prefix dct: <http://purl.org/dc/terms/> .
    @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
    @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
    @prefix dcat: <http://www.w3.org/ns/dcat#> .
    @prefix prov: <http://www.w3.org/ns/prov#> .

    <http://example.com/datasets/1> a dcat:Dataset ;
        prov:qualifiedAttribution   [
            a prov:Attribution ;
            prov:agent <http://example.com/agents/1> ;
            dcat:hadRole
                <http://registry.it.csiro.au/def/isotc211/CI_RoleCode/distributor>
        ] ;
    .
    """
    g1 = Graph().parse(data=resource.to_rdf(), format="turtle")
    g2 = Graph().parse(data=src, format="turtle")

    _isomorphic = isomorphic(g1, g2)
    if not _isomorphic:
        _dump_diff(g1, g2)
        pass
    assert _isomorphic
コード例 #6
0
def test_to_graph_should_return_keyword() -> None:
    """It returns a keyword graph isomorphic to spec."""
    resource = Dataset()
    resource.identifier = "http://example.com/datasets/1"
    _keyword = {}
    _keyword["nb"] = "Etnøkkelord"
    _keyword["nn"] = "Eitnøkkelord"
    _keyword["en"] = "Akeyword"
    resource.keyword = _keyword

    src = """
    @prefix dct: <http://purl.org/dc/terms/> .
    @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
    @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
    @prefix dcat: <http://www.w3.org/ns/dcat#> .

    <http://example.com/datasets/1> a dcat:Dataset ;
        dcat:keyword   "Akeyword"@en, "Etnøkkelord"@nb, "Eitnøkkelord"@nn ;
        .
    """
    g1 = Graph().parse(data=resource.to_rdf(), format="turtle")
    g2 = Graph().parse(data=src, format="turtle")

    _isomorphic = isomorphic(g1, g2)
    if not _isomorphic:
        _dump_diff(g1, g2)
        pass
    assert _isomorphic
コード例 #7
0
def test_to_graph_should_return_link_to_spatial_coverage() -> None:
    """It returns a spatial coverage graph isomorphic to spec."""
    dataset = Dataset()
    dataset.identifier = "http://example.com/datasets/1"
    # Add link to location:
    location = "http://publications.europa.eu/resource/authority/country/NOR"
    dataset.spatial_coverage = location

    src = """
    @prefix dct: <http://purl.org/dc/terms/> .
    @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
    @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
    @prefix dcat: <http://www.w3.org/ns/dcat#> .
    @prefix geosparql: <http://www.opengis.net/ont/geosparql#> .

    <http://example.com/datasets/1> a dcat:Dataset ;
        dct:spatial <http://publications.europa.eu/resource/authority/country/NOR> ;
    .
    """
    g1 = Graph().parse(data=dataset.to_rdf(), format="turtle")
    g2 = Graph().parse(data=src, format="turtle")

    _isomorphic = isomorphic(g1, g2)
    if not _isomorphic:
        _dump_diff(g1, g2)
        pass
    assert _isomorphic
コード例 #8
0
def test_to_graph_should_return_access_rights() -> None:
    """It returns a access_rights graph isomorphic to spec."""
    access_rights = ["PUBLIC", "RESTRICTED", "NON-PUBLIC"]
    for _r in access_rights:
        resource = Dataset()
        resource.identifier = "http://example.com/datasets/1"
        resource.access_rights = (
            f"http://publications.europa.eu/resource/authority/access-right/{_r}"
        )

        src = (
            "@prefix dct: <http://purl.org/dc/terms/> ."
            "@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> ."
            "@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> ."
            "@prefix dcat: <http://www.w3.org/ns/dcat#> .\n"
            "<http://example.com/datasets/1> a dcat:Dataset ;"
            "\tdct:accessRights\t"
            "<http://publications.europa.eu/resource/authority/access-right/"
            f"{_r}> ."
        )
        g1 = Graph().parse(data=resource.to_rdf(), format="turtle")
        g2 = Graph().parse(data=src, format="turtle")

        _isomorphic = isomorphic(g1, g2)
        if not _isomorphic:
            _dump_diff(g1, g2)
            pass
        assert _isomorphic
コード例 #9
0
def test_to_graph_should_return_skolemization(mocker: MockFixture) -> None:
    """It returns a endpointURL graph isomorphic to spec."""
    dataset = Dataset()

    src = """
    @prefix dct: <http://purl.org/dc/terms/> .
    @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
    @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
    @prefix dcat: <http://www.w3.org/ns/dcat#> .

    <http://wwww.digdir.no/.well-known/skolem/284db4d2-80c2-11eb-82c3-83e80baa2f94>
        a dcat:Dataset ;
        .
    """

    mocker.patch(
        "skolemizer.Skolemizer.add_skolemization",
        return_value=skolemization,
    )

    g1 = Graph().parse(data=dataset.to_rdf(), format="turtle")
    g2 = Graph().parse(data=src, format="turtle")

    _isomorphic = isomorphic(g1, g2)
    if not _isomorphic:
        _dump_diff(g1, g2)
        pass
    assert _isomorphic
コード例 #10
0
def test_to_graph_should_return_temporal_resolution() -> None:
    """It returns a temporal resolution graph isomorphic to spec."""
    dataset = Dataset()
    dataset.identifier = "http://example.com/datasets/1"
    dataset.temporal_resolution = "PT15M"

    src = """
    @prefix dct: <http://purl.org/dc/terms/> .
    @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
    @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
    @prefix dcat: <http://www.w3.org/ns/dcat#> .
    @prefix xsd:   <http://www.w3.org/2001/XMLSchema#> .

    <http://example.com/datasets/1> a dcat:Dataset ;
            dcat:temporalResolution "PT15M"^^xsd:duration ;
    .
    """
    g1 = Graph().parse(data=dataset.to_rdf(), format="turtle")
    g2 = Graph().parse(data=src, format="turtle")

    _isomorphic = isomorphic(g1, g2)
    if not _isomorphic:
        _dump_diff(g1, g2)
        pass
    assert _isomorphic
コード例 #11
0
def test_to_graph_should_return_temporal_coverage() -> None:
    """It returns a temporal coverage graph isomorphic to spec."""
    dataset = Dataset()
    dataset.identifier = "http://example.com/datasets/1"
    # Create PeriodOfTime:
    temporal_coverage = PeriodOfTime()
    temporal_coverage.start_date = "2019-12-31"
    temporal_coverage.end_date = "2020-12-31"
    # Add temporal_coverage to dataset:
    dataset.temporal_coverage = temporal_coverage

    src = """
    @prefix dct: <http://purl.org/dc/terms/> .
    @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
    @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
    @prefix dcat: <http://www.w3.org/ns/dcat#> .
    @prefix xsd:   <http://www.w3.org/2001/XMLSchema#> .

    <http://example.com/datasets/1> a dcat:Dataset ;
        dct:temporal [ a dct:PeriodOfTime ;
            dcat:startDate "2019-12-31"^^xsd:date ;
            dcat:endDate   "2020-12-31"^^xsd:date ;
        ]
    .
    """
    g1 = Graph().parse(data=dataset.to_rdf(), format="turtle")
    g2 = Graph().parse(data=src, format="turtle")

    _isomorphic = isomorphic(g1, g2)
    if not _isomorphic:
        _dump_diff(g1, g2)
        pass
    assert _isomorphic
コード例 #12
0
def test_to_graph_should_return_skolemization(mocker: MockFixture) -> None:
    """It returns a title graph isomorphic to spec."""
    relationship = Relationship()
    relationship.had_role = "http://www.iana.org/assignments/relation/original"
    dataset = Dataset()
    dataset.identifier = "http://example.com/datasets/1"
    relationship.relation = dataset

    src = """
    @prefix dct: <http://purl.org/dc/terms/> .
    @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
    @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
    @prefix dcat: <http://www.w3.org/ns/dcat#> .

    <http://wwww.digdir.no/.well-known/skolem/284db4d2-80c2-11eb-82c3-83e80baa2f94>
     a dcat:Relationship ;
        dct:relation   <http://example.com/datasets/1> ;
        dcat:hadRole <http://www.iana.org/assignments/relation/original>
    .
    """

    mocker.patch(
        "skolemizer.Skolemizer.add_skolemization",
        return_value=skolemization,
    )

    g1 = Graph().parse(data=relationship.to_rdf(), format="turtle")
    g2 = Graph().parse(data=src, format="turtle")

    _isomorphic = isomorphic(g1, g2)
    if not _isomorphic:
        _dump_diff(g1, g2)
        pass
    assert _isomorphic
コード例 #13
0
def test_to_graph_should_return_was_generated_by() -> None:
    """It returns a was generated by graph isomorphic to spec."""
    dataset = Dataset()
    dataset.identifier = "http://example.com/datasets/1"
    dataset.was_generated_by = "http://example.com/activity/1"

    src = """
    @prefix dct: <http://purl.org/dc/terms/> .
    @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
    @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
    @prefix dcat: <http://www.w3.org/ns/dcat#> .
    @prefix xsd:   <http://www.w3.org/2001/XMLSchema#> .
    @prefix prov: <http://www.w3.org/ns/prov#> .

    <http://example.com/datasets/1> a dcat:Dataset ;
            prov:wasGeneratedBy <http://example.com/activity/1> ;
    .
    """
    g1 = Graph().parse(data=dataset.to_rdf(), format="turtle")
    g2 = Graph().parse(data=src, format="turtle")

    _isomorphic = isomorphic(g1, g2)
    if not _isomorphic:
        _dump_diff(g1, g2)
        pass
    assert _isomorphic
コード例 #14
0
def test_to_graph_should_return_hasPolicy() -> None:
    """It returns a hasPolicy graph isomorphic to spec."""
    resource = Dataset()
    resource.identifier = "http://example.com/datasets/1"
    resource.has_policy = "http://example.com/policies/1"

    src = """
    @prefix dct: <http://purl.org/dc/terms/> .
    @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
    @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
    @prefix dcat: <http://www.w3.org/ns/dcat#> .
    @prefix odrl: <http://www.w3.org/ns/odrl/2/> .

    <http://example.com/datasets/1> a dcat:Dataset ;
        odrl:hasPolicy   <http://example.com/policies/1> ;
        .
    """
    g1 = Graph().parse(data=resource.to_rdf(), format="turtle")
    g2 = Graph().parse(data=src, format="turtle")

    _isomorphic = isomorphic(g1, g2)
    if not _isomorphic:
        _dump_diff(g1, g2)
        pass
    assert _isomorphic
コード例 #15
0
def _add_optional_dataset_props(dataset: Dataset, es_hit: Mapping) -> None:
    dataset.contactpoint = utils.create_contact(es_hit)
    dataset.creator = URI(os.environ["PUBLISHER"])
    dataset.frequency = URI(es_hit.get("periodicity", ""))
    dataset.license = URI(es_hit["license"]["url"])
    dataset.temporal_coverage = utils.create_temporal_coverage(
        es_hit["temporal"])
コード例 #16
0
def test_to_graph_should_return_distribution_as_graph() -> None:
    """It returns a distribution graph isomorphic to spec."""
    dataset = Dataset()
    dataset.identifier = "http://example.com/datasets/1"

    distribution1 = Distribution()
    distribution1.identifier = "http://example.com/distributions/1"
    dataset.distributions.append(distribution1)

    distribution2 = Distribution()
    distribution2.identifier = "http://example.com/distributions/2"
    dataset.distributions.append(distribution2)

    src = """
    @prefix dct: <http://purl.org/dc/terms/> .
    @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
    @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
    @prefix dcat: <http://www.w3.org/ns/dcat#> .
    @prefix prov: <http://www.w3.org/ns/prov#> .


    <http://example.com/datasets/1> a dcat:Dataset ;
        dcat:distribution   <http://example.com/distributions/1>,
                            <http://example.com/distributions/2>
        .
    """
    g1 = Graph().parse(data=dataset.to_rdf(include_distributions=False),
                       format="turtle")
    g2 = Graph().parse(data=src, format="turtle")

    _isomorphic = isomorphic(g1, g2)
    if not _isomorphic:
        _dump_diff(g1, g2)
        pass
    assert _isomorphic
コード例 #17
0
def test_to_graph_should_return_publisher_as_bnode() -> None:
    """It returns a name graph isomorphic to spec."""
    dataset = Dataset()
    dataset.identifier = "http://example.com/datasets/1"
    agent = Agent()
    agent.name = {"en": "James Bond", "nb": "Djeims Bånd"}
    dataset.publisher = agent

    src = """
    @prefix dct: <http://purl.org/dc/terms/> .
    @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
    @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
    @prefix dcat: <http://www.w3.org/ns/dcat#> .
    @prefix foaf: <http://xmlns.com/foaf/0.1/> .

    <http://example.com/datasets/1> a dcat:Dataset;
    dct:publisher   [a foaf:Agent ;
                       foaf:name "James Bond"@en, "Djeims Bånd"@nb ;
                    ] ;
    .
    """
    g1 = Graph().parse(data=dataset.to_rdf(), format="turtle")
    g2 = Graph().parse(data=src, format="turtle")

    _dump_turtle(g1)
    _isomorphic = isomorphic(g1, g2)
    if not _isomorphic:
        _dump_diff(g1, g2)
        pass
    assert _isomorphic
コード例 #18
0
def test_to_graph_should_return_link_to_spatial_coverage_with_location_triple(
) -> None:
    """It returns a spatial coverage graph isomorphic to spec."""
    dataset = Dataset()
    dataset.identifier = "http://example.com/datasets/1"
    # Create location:
    location = Location()
    location.identifier = "http://example.com/locations/1"
    location.centroid = "POINT(4.88412 52.37509)"
    # Add location to dataset:
    dataset.spatial_coverage = location

    src = """
    @prefix dct: <http://purl.org/dc/terms/> .
    @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
    @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
    @prefix dcat: <http://www.w3.org/ns/dcat#> .
    @prefix geosparql: <http://www.opengis.net/ont/geosparql#> .

    <http://example.com/datasets/1> a dcat:Dataset ;
        dct:spatial <http://example.com/locations/1> ;
    .

    <http://example.com/locations/1> a dct:Location ;
            dcat:centroid "POINT(4.88412 52.37509)"^^geosparql:asWKT ;
    .
    """
    g1 = Graph().parse(data=dataset.to_rdf(), format="turtle")
    g2 = Graph().parse(data=src, format="turtle")

    _isomorphic = isomorphic(g1, g2)
    if not _isomorphic:
        _dump_diff(g1, g2)
        pass
    assert _isomorphic
コード例 #19
0
def test_to_graph_should_return_catalog_without_datasets_as_graph() -> None:
    """It returns a catalog graph isomorphic to spec."""
    catalog = Catalog()
    catalog.identifier = "http://example.com/catalogs/1"

    dataset1 = Dataset()
    dataset1.identifier = "http://example.com/datasets/1"
    dataset1.title = {"nb": "Datasett 1", "en": "Dataset 1"}
    catalog.datasets.append(dataset1)

    dataset2 = Dataset()
    dataset2.identifier = "http://example.com/datasets/2"
    dataset2.title = {"nb": "Datasett 2", "en": "Dataset 2"}
    catalog.datasets.append(dataset2)

    src = """
    @prefix dct: <http://purl.org/dc/terms/> .
    @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
    @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
    @prefix dcat: <http://www.w3.org/ns/dcat#> .

    <http://example.com/catalogs/1> a dcat:Catalog ;
        dcat:dataset    <http://example.com/datasets/1> ,
                        <http://example.com/datasets/2> ;
    .
    """
    g1 = Graph().parse(data=catalog.to_rdf(include_datasets=False),
                       format="turtle")
    g2 = Graph().parse(data=src, format="turtle")

    _isomorphic = isomorphic(g1, g2)
    if not _isomorphic:
        _dump_diff(g1, g2)
        pass
    assert _isomorphic
コード例 #20
0
def test_to_graph_should_return_servesDataset_skolemization(
    mocker: MockFixture,
) -> None:
    """It returns a servesDataset graph isomorphic to spec."""
    dataService = DataService()
    dataService.identifier = "http://example.com/dataservices/1"

    dataset1 = Dataset()
    dataService.servesdatasets.append(dataset1)

    src = """
    @prefix dct: <http://purl.org/dc/terms/> .
    @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
    @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
    @prefix dcat: <http://www.w3.org/ns/dcat#> .

    <http://example.com/dataservices/1> a dcat:DataService ;
    dcat:servesDataset
        <http://wwww.digdir.no/.well-known/skolem/284db4d2-80c2-11eb-82c3-83e80baa2f94>
    .
    """

    mocker.patch(
        "skolemizer.Skolemizer.add_skolemization",
        return_value=skolemization,
    )

    g1 = Graph().parse(data=dataService.to_rdf(), format="turtle")
    g2 = Graph().parse(data=src, format="turtle")

    _isomorphic = isomorphic(g1, g2)
    if not _isomorphic:
        _dump_diff(g1, g2)
        pass
    assert _isomorphic
コード例 #21
0
def create_dataset(es_hit: Mapping) -> Dataset:
    dataset = Dataset()
    _add_mandatory_dataset_props(dataset, es_hit)
    _add_optional_dataset_props(dataset, es_hit)
    _add_distributions(dataset, es_hit["url"])

    return dataset
コード例 #22
0
def _add_mandatory_dataset_props(dataset: Dataset, es_hit: Mapping) -> None:
    dataset.title = {"nb": utils.remove_new_line(es_hit["title"])}
    dataset.identifier = URI(os.environ["DATASET_CONCEPT_IDENTIFIER"] +
                             es_hit["id"])
    dataset.landing_page = [
        os.environ["DATASET_CONCEPT_IDENTIFIER"] + es_hit["id"]
    ]
    dataset.description = {"nb": es_hit["description"]}
    dataset.publisher = URI(os.environ["PUBLISHER"])
    dataset.language = utils.create_language(es_hit["language"])
    dataset.access_rights = utils.create_access_rights(es_hit["accessRights"])
    dataset.spatial_coverage = utils.create_location(es_hit["spatial"])
コード例 #23
0
def test_to_graph_should_return_contactpoint() -> None:
    """It returns a contactpoint graph isomorphic to spec."""
    resource = Dataset()
    resource.identifier = "http://example.com/datasets/1"
    # Create contact:
    contact = Contact()
    contact.name = {
        "en": "Norwegian Digitalisation Agency",
        "nb": "Digitaliseringsdirektoratet",
    }
    contact.email = "*****@*****.**"
    contact.url = "https://digdir.no"
    contact.telephone = "12345678"
    # Set the contactpoint to new contact:
    resource.contactpoint = contact

    src = """
    @prefix dct: <http://purl.org/dc/terms/> .
    @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
    @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
    @prefix dcat: <http://www.w3.org/ns/dcat#> .
    @prefix vcard: <http://www.w3.org/2006/vcard/ns#> .

    <http://example.com/datasets/1> a dcat:Dataset ;
        dcat:contactPoint    [ a               vcard:Organization ;
                               vcard:hasEmail  <mailto:[email protected]> ;
                               vcard:hasOrganizationName
                                        "Norwegian Digitalisation Agency"@en,
                                        "Digitaliseringsdirektoratet"@nb ;
                               vcard:hasURL <https://digdir.no> ;
                               vcard:hasTelephone <tel:12345678> ;
                              ] ;
        .
    """
    g1 = Graph().parse(data=resource.to_rdf(), format="turtle")
    g2 = Graph().parse(data=src, format="turtle")

    _isomorphic = isomorphic(g1, g2)
    if not _isomorphic:
        _dump_diff(g1, g2)
        pass
    assert _isomorphic
コード例 #24
0
def test_to_graph_should_return_identifier_set_at_constructor() -> None:
    """It returns a identifier graph isomorphic to spec."""
    dataset = Dataset("http://example.com/datasets/1")

    src = """
    @prefix dct: <http://purl.org/dc/terms/> .
    @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
    @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
    @prefix dcat: <http://www.w3.org/ns/dcat#> .
    @prefix foaf:  <http://xmlns.com/foaf/0.1/> .

    <http://example.com/datasets/1> a dcat:Dataset .
    """
    g1 = Graph().parse(data=dataset.to_rdf(), format="turtle")
    g2 = Graph().parse(data=src, format="turtle")

    _isomorphic = isomorphic(g1, g2)
    if not _isomorphic:
        _dump_diff(g1, g2)
        pass
    assert _isomorphic
コード例 #25
0
def test_to_graph_should_return_servesDataset_as_graph() -> None:
    """It returns a servesDataset graph isomorphic to spec."""
    dataService = DataService()
    dataService.identifier = "http://example.com/dataservices/1"

    dataset1 = Dataset()
    dataset1.identifier = "http://example.com/datasets/1"
    dataService.servesdatasets.append(dataset1)

    dataset2 = Dataset()
    dataset2.identifier = "http://example.com/datasets/2"
    dataService.servesdatasets.append(dataset2)

    src = """
    @prefix dct: <http://purl.org/dc/terms/> .
    @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
    @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
    @prefix dcat: <http://www.w3.org/ns/dcat#> .

    <http://example.com/dataservices/1> a dcat:DataService ;
        dcat:servesDataset   <http://example.com/datasets/1>,
                             <http://example.com/datasets/2>
        .
    """
    g1 = Graph().parse(data=dataService.to_rdf(), format="turtle")
    g2 = Graph().parse(data=src, format="turtle")

    _isomorphic = isomorphic(g1, g2)
    if not _isomorphic:
        _dump_diff(g1, g2)
        pass
    assert _isomorphic
コード例 #26
0
def test_serialization_formats_that_should_work() -> None:
    """It returns no exception."""
    dataset = Dataset()
    dataset.identifier = "http://example.com/datasets/1"
    TURTLE = "text/turtle"
    XML = "application/rdf+xml"
    JSONLD = "application/ld+json"
    NT = "application/n-triples"
    N3 = "text/n3"

    _g = Graph()
    _g.parse(data=dataset.to_rdf(format=TURTLE), format=TURTLE)
    _g.parse(data=dataset.to_rdf(format=XML), format=XML)
    _g.parse(data=dataset.to_rdf(format=JSONLD), format=JSONLD)
    _g.parse(data=dataset.to_rdf(format=NT, encoding=None), format=NT)
    _g.parse(data=dataset.to_rdf(format=N3), format=N3)
コード例 #27
0
def test_to_graph_should_return_description() -> None:
    """It returns a description graph isomorphic to spec."""
    resource = Dataset()
    resource.identifier = "http://example.com/datasets/1"
    resource.description = {"nb": "Beskrivelse", "en": "Description"}

    src = """
    @prefix dct: <http://purl.org/dc/terms/> .
    @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
    @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
    @prefix dcat: <http://www.w3.org/ns/dcat#> .

    <http://example.com/datasets/1> a dcat:Dataset ;
        dct:description   "Description"@en, "Beskrivelse"@nb ;
        .
    """
    g1 = Graph().parse(data=resource.to_rdf(), format="turtle")
    g2 = Graph().parse(data=src, format="turtle")

    _isomorphic = isomorphic(g1, g2)
    if not _isomorphic:
        _dump_diff(g1, g2)
        pass
    assert _isomorphic
コード例 #28
0
def test_to_graph_should_return_dct_identifier_as_graph() -> None:
    """It returns a dct_identifier graph isomorphic to spec."""
    dataset = Dataset()
    dataset.identifier = "http://example.com/datasets/1"
    dataset.dct_identifier = "Dataset_123456789"

    src = """
    @prefix dct: <http://purl.org/dc/terms/> .
    @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
    @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
    @prefix dcat: <http://www.w3.org/ns/dcat#> .

    <http://example.com/datasets/1>    a dcat:Dataset ;
        dct:identifier "Dataset_123456789";
    .
    """
    g1 = Graph().parse(data=dataset.to_rdf(), format="turtle")
    g2 = Graph().parse(data=src, format="turtle")

    _isomorphic = isomorphic(g1, g2)
    if not _isomorphic:
        _dump_diff(g1, g2)
        pass
    assert _isomorphic
コード例 #29
0
def test_to_graph_should_return_frequency() -> None:
    """It returns a frequency graph isomorphic to spec."""
    dataset = Dataset()
    dataset.identifier = "http://example.com/datasets/1"
    dataset.frequency = "http://purl.org/cld/freq/daily"

    src = """
    @prefix dct: <http://purl.org/dc/terms/> .
    @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
    @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
    @prefix dcat: <http://www.w3.org/ns/dcat#> .

    <http://example.com/datasets/1> a dcat:Dataset ;
        dct:accrualPeriodicity   <http://purl.org/cld/freq/daily> ;
    .
    """
    g1 = Graph().parse(data=dataset.to_rdf(), format="turtle")
    g2 = Graph().parse(data=src, format="turtle")

    _isomorphic = isomorphic(g1, g2)
    if not _isomorphic:
        _dump_diff(g1, g2)
        pass
    assert _isomorphic
コード例 #30
0
def test_to_graph_should_return_dataset_skolemization(
        mocker: MockFixture) -> None:
    """It returns a dataset graph isomorphic to spec."""
    catalog = Catalog()
    catalog.identifier = "http://example.com/catalogs/1"

    dataset1 = Dataset()
    dataset1.title = {"nb": "Datasett 1", "en": "Dataset 1"}
    catalog.datasets.append(dataset1)

    dataset2 = Dataset()
    dataset2.title = {"nb": "Datasett 2", "en": "Dataset 2"}
    catalog.datasets.append(dataset2)

    src = """
    @prefix dct: <http://purl.org/dc/terms/> .
    @prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
    @prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
    @prefix dcat: <http://www.w3.org/ns/dcat#> .

    <http://example.com/catalogs/1> a dcat:Catalog ;
        dcat:dataset
            <http://wwww.digdir.no/.well-known/skolem/21043186-80ce-11eb-9829-cf7c8fc855ce> ,
            <http://wwww.digdir.no/.well-known/skolem/284db4d2-80c2-11eb-82c3-83e80baa2f94> ;
    .
    <http://wwww.digdir.no/.well-known/skolem/284db4d2-80c2-11eb-82c3-83e80baa2f94>
     a dcat:Dataset ;
        dct:title   "Dataset 1"@en, "Datasett 1"@nb ;
    .
    <http://wwww.digdir.no/.well-known/skolem/21043186-80ce-11eb-9829-cf7c8fc855ce>
     a dcat:Dataset ;
        dct:title   "Dataset 2"@en, "Datasett 2"@nb ;
    .

    """

    skolemutils = SkolemUtils()

    mocker.patch(
        "skolemizer.Skolemizer.add_skolemization",
        side_effect=skolemutils.get_skolemization,
    )

    g1 = Graph().parse(data=catalog.to_rdf(), format="turtle")
    g2 = Graph().parse(data=src, format="turtle")

    _isomorphic = isomorphic(g1, g2)
    if not _isomorphic:
        _dump_diff(g1, g2)
        pass
    assert _isomorphic