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
def _add_mandatory_distribution_props(distribution: Distribution, resource: Mapping) -> None: distribution.formats = [create_format(resource["format"])] distribution.access_URL = URI(resource["path"]) distribution.identifier = URI(resource["path"]) distribution.license = URI( "http://creativecommons.org/licenses/by/4.0/deed.no")
def test_to_graph_should_return_packaging_format() -> None: """It returns a packaging format graph isomorphic to spec.""" distribution = Distribution() distribution.identifier = "http://example.com/distributions/1" distribution.package_format = ( "http://publications.europa.eu/resource/authority/file-type/TAR") 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/distributions/1> a dcat:Distribution ; dcat:packageFormat \ <http://publications.europa.eu/resource/authority/file-type/TAR> . """ g1 = Graph().parse(data=distribution.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
def test_to_graph_should_return_compression_format() -> None: """It returns a compression format graph isomorphic to spec.""" distribution = Distribution() distribution.identifier = "http://example.com/distributions/1" distribution.compression_format = ( "http://www.iana.org/assignments/media-types/application/gzip") 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/distributions/1> a dcat:Distribution ; dcat:compressFormat \ <http://www.iana.org/assignments/media-types/application/gzip> . """ g1 = Graph().parse(data=distribution.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
def test_to_graph_should_return_conforms_to() -> None: """It returns a conforms to graph isomorphic to spec.""" distribution = Distribution() distribution.identifier = "http://example.com/distributions/1" distribution.conforms_to.append("http://example.com/standards/1") distribution.conforms_to.append("http://example.com/standards/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/distributions/1> a dcat:Distribution ; dct:conformsTo <http://example.com/standards/1> , <http://example.com/standards/2> ; . """ g1 = Graph().parse(data=distribution.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
def test_to_graph_should_return_temporal_resolution() -> None: """It returns a temporal resolution graph isomorphic to spec.""" distribution = Distribution() distribution.identifier = "http://example.com/distributions/1" distribution.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/distributions/1> a dcat:Distribution ; dcat:temporalResolution "PT15M"^^xsd:duration ; . """ g1 = Graph().parse(data=distribution.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
def test_to_graph_should_return_byte_size() -> None: """It returns a byte size graph isomorphic to spec.""" distribution = Distribution() distribution.identifier = "http://example.com/distributions/1" # byte_size is an xsd:decimal: distribution.byte_size = Decimal(5120.0) 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/distributions/1> a dcat:Distribution ; dcat:byteSize "5120.0"^^xsd:decimal ; . """ g1 = Graph().parse(data=distribution.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
def test_to_graph_should_return_access_service_skolemized( mocker: MockFixture) -> None: """It returns a access service graph isomorphic to spec.""" distribution = Distribution() distribution.identifier = "http://example.com/distributions/1" service = DataService() distribution.access_service = service 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/distributions/1> a dcat:Distribution ; dcat:accessService <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=distribution.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
def test_to_graph_should_return_access_service() -> None: """It returns a access service graph isomorphic to spec.""" distribution = Distribution() distribution.identifier = "http://example.com/distributions/1" service = DataService() service.identifier = "http://example.com/dataservices/1" distribution.access_service = service 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/distributions/1> a dcat:Distribution ; dcat:accessService <http://example.com/dataservices/1> ; . """ g1 = Graph().parse(data=distribution.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
def test_to_graph_should_return_has_policy() -> None: """It returns a has_policy graph isomorphic to spec.""" distribution = Distribution() distribution.identifier = "http://example.com/distributions/1" distribution.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/distributions/1> a dcat:Distribution ; odrl:hasPolicy <http://example.com/policies/1> ; . """ g1 = Graph().parse(data=distribution.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
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: distribution = Distribution() distribution.identifier = "http://example.com/distributions/1" distribution.access_rights = ( f"http://publications.europa.eu/distribution/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/distributions/1> a dcat:Distribution ;" "\tdct:accessRights\t" "<http://publications.europa.eu/distribution/authority/access-right/" f"{_r}> .") g1 = Graph().parse(data=distribution.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
def create_html_distribution(dp_metadata: dict): html_distribution = Distribution() html_distribution.title = {"nb": dp_metadata["title"]} html_distribution.formats = ["text/html"] html_distribution.description = {"nb": dp_metadata["description"]} html_distribution.identifier = URI( os.environ["DATASET_CONCEPT_IDENTIFIER"] + dp_metadata["id"]) html_distribution.license = URI( "http://creativecommons.org/licenses/by/4.0/deed.no") html_distribution.access_URL = URI( os.environ["DATASET_CONCEPT_IDENTIFIER"] + dp_metadata["id"]) return html_distribution
def test_to_graph_should_return_description() -> None: """It returns a description graph isomorphic to spec.""" distribution = Distribution() distribution.identifier = "http://example.com/distributions/1" distribution.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/distributions/1> a dcat:Distribution ; dct:description "Description"@en, "Beskrivelse"@nb ; . """ g1 = Graph().parse(data=distribution.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