From 8cc95c8c02c2638ae6411fb2bfd5da31df538a11 Mon Sep 17 00:00:00 2001 From: MarcoHuebner <57489799+MarcoHuebner@users.noreply.github.com> Date: Tue, 20 Sep 2022 09:40:23 +0200 Subject: [PATCH] Minor requested updates, #48. --- src/pygenesis/helloworld.py | 4 ++-- src/pygenesis/profile.py | 12 +++++++++--- tests/test_profile.py | 12 +++++++----- 3 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/pygenesis/helloworld.py b/src/pygenesis/helloworld.py index bbcabfb..771f897 100644 --- a/src/pygenesis/helloworld.py +++ b/src/pygenesis/helloworld.py @@ -21,7 +21,7 @@ def whoami() -> str: _check_invalid_status_code(response.status_code) - return str(response.text) + return response.text def logincheck() -> str: @@ -46,4 +46,4 @@ def logincheck() -> str: # and misleading usage of "Status" key in API response _check_invalid_status_code(response.status_code) - return str(response.text) + return response.text diff --git a/src/pygenesis/profile.py b/src/pygenesis/profile.py index 36e0207..c64e883 100644 --- a/src/pygenesis/profile.py +++ b/src/pygenesis/profile.py @@ -1,5 +1,7 @@ """Module provides wrapper for Profile GENESIS REST-API functions.""" +import logging + from pygenesis.config import ( _write_config, get_config_path_from_settings, @@ -7,8 +9,10 @@ ) from pygenesis.http_helper import get_data_from_endpoint +logger = logging.getLogger(__name__) + -def password(new_password: str) -> str: +def change_password(new_password: str) -> str: """ Changes Genesis REST-API password and updates local config. @@ -41,6 +45,8 @@ def password(new_password: str) -> str: config["GENESIS API"]["password"] = new_password _write_config(config, get_config_path_from_settings()) + logger.info("Password changed successfully!") + return response_text @@ -56,11 +62,11 @@ def remove_result(name: str, area: str = "all") -> str: Returns: str: text response from Destatis """ - params = {"name": name, "area": area} + params = {"name": name, "area": area, "language": "de"} # remove 'Ergebnistabelle' with previously defined parameters response_text = get_data_from_endpoint( - endpoint="profile", method="removeresult?", params=params + endpoint="profile", method="removeresult", params=params ) return response_text diff --git a/tests/test_profile.py b/tests/test_profile.py index 621e682..cf5b04c 100644 --- a/tests/test_profile.py +++ b/tests/test_profile.py @@ -5,7 +5,7 @@ import pytest from mock import patch -from pygenesis.profile import password, remove_result +from pygenesis.profile import change_password, remove_result from tests.test_http_helper import _generic_request_status @@ -21,7 +21,9 @@ def cache_dir(tmp_path_factory): @patch("pygenesis.profile.get_config_path_from_settings") @patch("pygenesis.profile.get_data_from_endpoint") @patch("pygenesis.profile.load_config") -def test_password(mock_config, mock_requests, mock_config_dir, cache_dir): +def test_change_password( + mock_config, mock_requests, mock_config_dir, cache_dir +): # mock configparser to be able to test writing of new password config = ConfigParser() config["GENESIS API"] = { @@ -33,13 +35,13 @@ def test_password(mock_config, mock_requests, mock_config_dir, cache_dir): mock_requests.return_value = _generic_request_status() mock_config_dir.return_value = cache_dir / "config.ini" - password("new_password") + change_password("new_password") @patch("pygenesis.profile.get_config_path_from_settings") @patch("pygenesis.profile.get_data_from_endpoint") @patch("pygenesis.profile.load_config") -def test_password_keyerror( +def test_change_password_keyerror( mock_config, mock_requests, mock_config_dir, cache_dir ): # define empty config (no password) @@ -48,7 +50,7 @@ def test_password_keyerror( mock_config_dir.return_value = cache_dir with pytest.raises(KeyError) as e: - password("new_password") + change_password("new_password") assert ( "Password not found in config! Please make sure \ init_config() was run properly & your user data is set correctly!"