Skip to content

Commit

Permalink
Minor requested updates, #48.
Browse files Browse the repository at this point in the history
  • Loading branch information
MarcoHuebner committed Sep 20, 2022
1 parent a440b99 commit 8cc95c8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/pygenesis/helloworld.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def whoami() -> str:

_check_invalid_status_code(response.status_code)

return str(response.text)
return response.text


def logincheck() -> str:
Expand All @@ -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
12 changes: 9 additions & 3 deletions src/pygenesis/profile.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,18 @@
"""Module provides wrapper for Profile GENESIS REST-API functions."""

import logging

from pygenesis.config import (
_write_config,
get_config_path_from_settings,
load_config,
)
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.
Expand Down Expand Up @@ -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


Expand All @@ -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
12 changes: 7 additions & 5 deletions tests/test_profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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"] = {
Expand All @@ -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)
Expand All @@ -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!"
Expand Down

0 comments on commit 8cc95c8

Please sign in to comment.