def _add_mandatory_concept_props(concept, es_hit) -> None: concept.identifier = os.environ["TERM_CONCEPT_IDENTIFIER"] + es_hit["id"] concept.term = {"name": {"nb": utils.remove_new_line(es_hit["title"])}} concept.definition = utils.create_definition( { "nb": utils.remove_new_line( es_hit["content"].get("clean_definisjon")) }, { "text": { "nb": utils.remove_new_line( es_hit["content"].get("clean_kilde")) } }) concept.publisher = os.environ["PUBLISHER"]
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"])
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"])
def _add_optional_concept_props(concept, es_hit) -> None: try: concept.subject = { "nb": utils.remove_new_line(es_hit["content"]["fagomrade"]) } except KeyError: concept.subject = {"nb": ""} concept.contactpoint = utils.create_contact( {"contactPoint": { "email": os.environ["TERM_CONCEPT_CONTACT"] }}) date = dt.datetime.strptime(es_hit["content"]["oppdatert"].split('T')[0], "%Y-%m-%d") concept.modified = dt.date(year=date.year, month=date.month, day=date.day)
def test_remove_new_line_None(self): string = None expected_washed_string = "" washed_string = utils.remove_new_line(string) self.assertEqual(washed_string, expected_washed_string)
def test_remove_new_line_valid(self): string = "test\r\ntest\r\n" expected_washed_string = "testtest" washed_string = utils.remove_new_line(string) self.assertEqual(washed_string, expected_washed_string)