generated from CorrelAid/python-bare-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added most of the methods from helloworld and profile endpoint - this…
… time for real, without tests so far, #48
- Loading branch information
1 parent
3ec97d3
commit f058d7b
Showing
4 changed files
with
99 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
"""Module provides wrapper for HelloWorld GENESIS REST-API functions.""" | ||
|
||
import requests | ||
|
||
from pygenesis.config import load_config | ||
from pygenesis.http_helper import _check_invalid_status_code | ||
|
||
config = load_config() | ||
|
||
|
||
# TODO: Write tests | ||
def whoami() -> str: | ||
""" | ||
Wrapper method which constructs an URL for testing the Destatis API | ||
whoami method, which returns host name and IP address. | ||
Returns: | ||
str: text test response from Destatis | ||
""" | ||
url = f"{config['GENESIS API']['base_url']}" + "helloworld/whoami" | ||
|
||
response = requests.get(url) | ||
|
||
_check_invalid_status_code(response.status_code) | ||
|
||
return response.text | ||
|
||
|
||
def logincheck(): | ||
""" | ||
Wrapper method which constructs an URL for testing the Destatis API | ||
logincheck method, which tests the login credentials (from the config.ini). | ||
Returns: | ||
str: text logincheck response from Destatis | ||
""" | ||
url = f"{config['GENESIS API']['base_url']}" + "helloworld/logincheck" | ||
|
||
params = { | ||
"username": config["GENESIS API"]["username"], | ||
"password": config["GENESIS API"]["password"], | ||
} | ||
|
||
response = requests.get(url, params=params) | ||
|
||
# NOTE: Cannot use get_response_from_endpoint due to colliding | ||
# and misleading usage of "Status" key in response | ||
_check_invalid_status_code(response.status_code) | ||
|
||
return response.text |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
"""Module provides wrapper for Profile GENESIS REST-API functions.""" | ||
|
||
from pygenesis.config import ( | ||
_write_config, | ||
get_config_path_from_settings, | ||
load_config, | ||
) | ||
from pygenesis.http_helper import get_response_from_endpoint | ||
|
||
|
||
# TODO: write tests | ||
def password(new_password: str): | ||
""" | ||
Changes Genesis REST-API password and updates local config. | ||
Args: | ||
new_password (str): New password for the Genesis REST-API | ||
Returns: | ||
str: text response from Destatis | ||
""" | ||
params = { | ||
"new": new_password, | ||
"repeat": new_password, | ||
} | ||
|
||
# load config.ini beforehand, to ensure passwords are changed at the same time | ||
config = load_config() | ||
try: | ||
config["GENESIS API"]["password"] | ||
except KeyError as e: | ||
raise KeyError( | ||
e, | ||
"Password not found in config! Please make sure \ | ||
init_config() was run properly & your user data is set correctly!", | ||
) | ||
|
||
# change remote password | ||
response = get_response_from_endpoint("profile", "password", params) | ||
# change local password | ||
config["GENESIS API"]["password"] = new_password | ||
_write_config(config, get_config_path_from_settings()) | ||
|
||
return response.text | ||
|
||
|
||
def remove_result(): | ||
pass |