From 257960607643a244d12b4bf4ea1eafe85e4fa7cf Mon Sep 17 00:00:00 2001 From: Fjodor van Rijsselberg Date: Wed, 5 Apr 2023 17:30:42 +0200 Subject: [PATCH] Changed the env setup to fix the tests. --- dot_env_example | 2 +- src/enhancers/MetadataEnhancer.py | 6 ++---- src/main.py | 5 +++-- src/tests/test_enhancer.py | 4 ++-- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/dot_env_example b/dot_env_example index e2e8143..aac10bf 100644 --- a/dot_env_example +++ b/dot_env_example @@ -7,7 +7,7 @@ PYTHONPATH: "/root/src/" # URL'S KEYWORD_VOCABULARY_URL='https://fuseki.odissei.nl/skosmos/sparql' VARIABLE_VOCABULARY_URL='https://fuseki.odissei.nl/skosmos/sparql' -GRLC_API_URL='https://grlc.odissei.nl/api-git/odissei-data/grlc/' +ROOT_API_URL='https://grlc.odissei.nl/api-git/odissei-data/grlc/' # Endpoints KEYWORD_ENDPOINT='matchElsstTermForKeyword' diff --git a/src/enhancers/MetadataEnhancer.py b/src/enhancers/MetadataEnhancer.py index 0f48eca..929219a 100644 --- a/src/enhancers/MetadataEnhancer.py +++ b/src/enhancers/MetadataEnhancer.py @@ -5,8 +5,6 @@ from .utils import _try_for_key -GRLC_API_URL = os.environ['GRLC_API_URL'] - class MetadataEnhancer: """ A super class used for enhancing Dataverse metadata. @@ -64,7 +62,7 @@ def get_value_from_metadata(self, metadata_field_name: str, return metadata_field['value'] def query_matched_terms(self, value_to_match: str) -> dict: - """ Queries a grlc endpoint for terms matching the given value. + """ Queries an endpoint for terms matching the given value. :param value_to_match: The value to use for finding matches. """ @@ -79,7 +77,7 @@ def query_matched_terms(self, value_to_match: str) -> dict: 'endpoint': self.sparql_endpoint, } - url = GRLC_API_URL + self.endpoint + url = self.endpoint response = requests.get( url, params=params, diff --git a/src/main.py b/src/main.py index b0dbc14..83025d3 100644 --- a/src/main.py +++ b/src/main.py @@ -9,6 +9,7 @@ app = FastAPI() +ROOT_API_URL = os.environ['ROOT_API_URL'] KEYWORD_ENDPOINT = os.environ['KEYWORD_ENDPOINT'] VARIABLE_ENDPOINT = os.environ['VARIABLE_ENDPOINT'] KEYWORD_VOCABULARY_URL = os.environ['KEYWORD_VOCABULARY_URL'] @@ -26,7 +27,7 @@ async def dataverse_keyword_enhancer( enhancer_input: EnhancerInput) -> dict: keyword_enhancer = KeywordEnhancer( enhancer_input.metadata, - KEYWORD_ENDPOINT, + ROOT_API_URL + KEYWORD_ENDPOINT, KEYWORD_VOCABULARY_URL ) keyword_enhancer.enhance_metadata() @@ -37,7 +38,7 @@ async def dataverse_keyword_enhancer( async def dataverse_metadata_enhancer(enhancer_input: EnhancerInput) -> dict: variable_enhancer = VariableEnhancer( enhancer_input.metadata, - VARIABLE_ENDPOINT, + ROOT_API_URL + VARIABLE_ENDPOINT, VARIABLE_VOCABULARY_URL ) variable_enhancer.enhance_metadata() diff --git a/src/tests/test_enhancer.py b/src/tests/test_enhancer.py index 6f4ccca..a8aa906 100644 --- a/src/tests/test_enhancer.py +++ b/src/tests/test_enhancer.py @@ -29,6 +29,7 @@ def cbs_variable_output(): def keyword_enhancer(cbs_metadata): return KeywordEnhancer( cbs_metadata, + 'https://grlc.odissei.nl/api-git/odissei-data/grlc/' 'matchElsstTermForKeyword', 'https://fuseki.odissei.nl/skosmos/sparql' ) @@ -38,7 +39,7 @@ def keyword_enhancer(cbs_metadata): def variable_enhancer(cbs_metadata): return VariableEnhancer( cbs_metadata, - 'getCbsVarUri', + 'https://grlc.odissei.nl/api-git/odissei-data/grlc/getCbsVarUri', 'https://fuseki.odissei.nl/skosmos/sparql' ) @@ -84,7 +85,6 @@ def test_query_matched_terms(variable_enhancer): assert 'bindings' in terms_dict['results'] assert len(terms_dict['results']['bindings']) == 0 - # def test_add_terms_to_metadata(variable_enhancer): # # Test adding terms to a variable metadata field # terms = [