From f8184cca404e2b54a4fbd91d86a915432176c3d6 Mon Sep 17 00:00:00 2001 From: "k.dabrock" Date: Thu, 26 Sep 2024 18:58:33 +0200 Subject: [PATCH] make dev client default to dev db --- src/builda_client/config.yml | 2 +- src/builda_client/dev_client.py | 8 +++++--- tests/test_dev_client.py | 17 ++++++++++++++--- 3 files changed, 20 insertions(+), 7 deletions(-) diff --git a/src/builda_client/config.yml b/src/builda_client/config.yml index fcf999a..4d032b2 100644 --- a/src/builda_client/config.yml +++ b/src/builda_client/config.yml @@ -9,7 +9,7 @@ development: production: api_address: https://ethos-builda.fz-juelich.de -base_url: /api/v0/ +base_url: /api/v8_20240916/ nominatim: host: 134.94.117.112 diff --git a/src/builda_client/dev_client.py b/src/builda_client/dev_client.py index b4e59eb..9a63c3a 100644 --- a/src/builda_client/dev_client.py +++ b/src/builda_client/dev_client.py @@ -187,8 +187,9 @@ def __init__( self, username: str, password: str, - phase: Phase = Phase.PRODUCTION, + phase: Phase = Phase.DEVELOPMENT, proxy: bool = False, + version: str = "v0" ): """Constructor. @@ -198,7 +199,8 @@ def __init__( username (str): Username for API authentication. password (str): Password for API authentication. phase (Phase, optional): The 'phase' the client is used in, i.e. which - database to access. Defaults to Phase.PRODUCTION. + database to access. Defaults to Phase.DEVELOPMENT. + version (str, optional): The API version. Defaults to v0 """ super().__init__() @@ -209,7 +211,7 @@ def __init__( address = self.config["proxy_address"] if proxy else self.config[self.phase.value]["api_address"] - self.base_url = f"""{address}{self.config['base_url']}""" + self.base_url = f"""{address}/api/{version}/""" self.authentication_url = f"""{address}{self.AUTH_URL}""" self.api_token = self.__get_authentication_token() diff --git a/tests/test_dev_client.py b/tests/test_dev_client.py index a292afc..d464be8 100644 --- a/tests/test_dev_client.py +++ b/tests/test_dev_client.py @@ -100,6 +100,17 @@ def test_get_buildings_base_no_type(self): buildings = self.testee.get_buildings_base(nuts_code='01058007') self.__then_result_list_min_length_returned(buildings, 1) + # Commented out so this will not unintentionally overwrite existing data + # def test_update_mobility_preference(self): + # self.__given_client_authenticated() + # person_count = 10000 + # person_ids = self.testee.execute_query(f"SELECT id::varchar from data.persons limit {person_count}") + # person_ids = [x for xs in person_ids for x in xs] + # data = [] + # for p in person_ids: + # data.append((p, '{"pref": "train"}')) + + # self.testee.update_mobility_preference(data) @pytest.mark.parametrize( "nuts_level,country,expected_min_count", @@ -137,9 +148,9 @@ def test_get_pv_potential_statistics_succeeds(self, nuts_level, country, expecte # GIVEN def __given_client_authenticated(self, proxy: bool = False) -> None: - username = os.getenv('API_USERNAME') - password = os.getenv('API_PASSWORD') - self.testee = BuildaDevClient(proxy=proxy, username=username, password=password, phase=Phase.PRODUCTION) + username = os.getenv('API_USERNAME_DEV') + password = os.getenv('API_PASSWORD_DEV') + self.testee = BuildaDevClient(proxy=proxy, username=username, password=password, phase=Phase.DEVELOPMENT) # THEN