コード例 #1
0
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")
コード例 #2
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"])
コード例 #3
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.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"])
コード例 #4
0
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
コード例 #5
0
    def _create_dataservice(self, url: Optional[str] = None) -> None:
        """Creates a dataservice instance and appends it to list of dataservices."""
        self._dataservice = DataService()
        if url:
            self._dataservice.endpointURL = url
        self._dataservice.endpointDescription = self.endpointdescription

        try:
            self._dataservice.publisher = self.publisher
        except AttributeError:
            pass

        try:
            self._dataservice.conformsTo = self.conforms_to
        except AttributeError:
            self.conforms_to: List[str] = []

        self._parse_specification()

        # We may be given an identifier "template" ending with {id}.
        # We create the identifier and url based on title and complete the identifer:
        id = (self._dataservice.title["en"]
              if url is None else self._dataservice.title["en"] + url)
        self._dataservice.identifier = URI(
            self.identifier.format(id=create_id(id)))

        self.dataservices.append(self._dataservice)
コード例 #6
0
 def test_create_access_rights_opendata(self):
     inputs = ["open", "opendata", "åpne data"]
     expected_out = URI(
         "http://publications.europa.eu/resource/authority/access-right/PUBLIC"
     )
     for input_access in inputs:
         output = create_access_rights(input_access)
         self.assertEqual(expected_out, output)
コード例 #7
0
    def test_create_location(self):
        expected_location = Location()
        expected_location.identifier = URI("http://sws.geonames.org/3144096/")

        countries = ["Norge", "Norway"]
        for country in countries:
            location = create_location(country)
            self.assertEqual(expected_location.identifier, location.identifier)
コード例 #8
0
def _add_optional_distribution_props(distribution: Distribution,
                                     resource: Mapping) -> None:
    distribution.title = {
        "nb": resource["name"].replace("_", " ").capitalize()
    }
    distribution.description = {
        "nb": utils.remove_new_line(resource["description"])
    }
    distribution.download_URL = URI(resource["path"])
コード例 #9
0
 def publisher(self, publisher: str) -> None:
     self._publisher = URI(publisher)
     for dataservice in self._dataservices:
         dataservice.publisher = publisher
コード例 #10
0
 def endpointdescription(self, endpointdescription: str) -> None:
     self._endpointdescription = URI(endpointdescription)
コード例 #11
0
ファイル: api.py プロジェクト: navikt/dakan-api-digdir
def _add_mandatory_props(api: DataService, es_hit: Mapping) -> None:
    api.title = {"nb": es_hit["title"]}
    api.identifier = es_hit["id"]
    api.publisher = URI(os.environ["PUBLISHER"])
    if es_hit.get("master") == "NAV API PORTAL":
        api.landing_page = [os.environ["NAV_API_PORTAL"]]
コード例 #12
0
def _add_optional_catalog_props(catalog: Catalog) -> None:
    catalog.homepage = URI(os.environ["CATALOG_HOMEPAGE"])
コード例 #13
0
def _add_mandatory_catalog_props(catalog: Catalog) -> None:
    catalog.title = {"nb": "NAV åpne APIer"}
    catalog.identifier = os.environ["COLLECTION_IDENTIFIER"]
    catalog.publisher = URI(os.environ["PUBLISHER"])
コード例 #14
0
def test_valid_uri() -> None:
    """It does not raise an exception."""
    _valid_uri = "http://example.com/uris/1"
    _ = URI(_valid_uri)
コード例 #15
0
def test_invalid_uri() -> None:
    """It does raise an InvalidURIError."""
    _invalid_uri = "http://example.com/an invalid path"
    with pytest.raises(InvalidURIError):
        _ = URI(_invalid_uri)
コード例 #16
0
def test_valid_uri_as_str() -> None:
    """It does return the correct uri as str."""
    valid_uri = "http://example.com/uris/1"
    uri = URI(valid_uri)

    assert uri == valid_uri
コード例 #17
0
def create_location(spatial: str) -> Location:
    location = Location()
    location.identifier = URI("http://sws.geonames.org/3144096/")
    return location
コード例 #18
0
def _add_optional_props(api: DataService, es_hit: Mapping) -> None:
    api.publisher = URI(os.environ["PUBLISHER"])
    api.description = {"nb": es_hit["content"]["description"]}
    api.endpointURL = es_hit["content"]["url"]
    api.endpointDescription = es_hit["content"]["swagger"]