-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #220 from hkad98/PSDK-123
PSDK-123 GoodPandas classmethod to load credentials from config file Reviewed-by: Jan Soubusta https://github.com/jaceksan
- Loading branch information
Showing
6 changed files
with
101 additions
and
9 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 @@ | ||
# (C) 2023 GoodData Corporation |
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,17 @@ | ||
# (C) 2023 GoodData Corporation | ||
default: | ||
host: http://abc:3000 | ||
token: 123 | ||
custom_headers: | ||
Host: localhost | ||
extra_user_agent: xyz | ||
custom: | ||
host: http://xyz:3000 | ||
token: 456 | ||
custom_headers: | ||
Host: localhost123 | ||
extra_user_agent: abc | ||
wrong: | ||
custom_headers: | ||
Host: localhost123 | ||
extra_user_agent: abc |
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,49 @@ | ||
# (C) 2023 GoodData Corporation | ||
from __future__ import annotations | ||
|
||
from pathlib import Path | ||
from typing import Any | ||
|
||
import yaml | ||
|
||
from gooddata_pandas import GoodPandas | ||
|
||
_current_dir = Path(__file__).parent.absolute() | ||
PROFILES_PATH = _current_dir / "profiles" / "profiles.yaml" | ||
|
||
|
||
def load_profiles_content() -> dict: | ||
with open(PROFILES_PATH, "r", encoding="utf-8") as f: | ||
return yaml.safe_load(f) | ||
|
||
|
||
def are_same_check(profile_data: dict[str, Any], good_pandas: GoodPandas): | ||
assert profile_data["host"] == good_pandas.sdk.client._hostname | ||
assert profile_data["token"] == good_pandas.sdk.client._token | ||
assert profile_data["custom_headers"] == good_pandas.sdk.client._custom_headers | ||
|
||
|
||
def test_default_profile(): | ||
profile = "default" | ||
good_pandas = GoodPandas.create_from_profile(profiles_path=PROFILES_PATH) | ||
data = load_profiles_content() | ||
|
||
are_same_check(data[profile], good_pandas) | ||
|
||
|
||
def test_other_profile(): | ||
profile = "custom" | ||
good_pandas = GoodPandas.create_from_profile(profile=profile, profiles_path=PROFILES_PATH) | ||
data = load_profiles_content() | ||
|
||
are_same_check(data[profile], good_pandas) | ||
|
||
|
||
def test_wrong_profile(): | ||
profile = "wrong" | ||
try: | ||
GoodPandas.create_from_profile(profile=profile, profiles_path=PROFILES_PATH) | ||
except ValueError: | ||
assert True | ||
else: | ||
assert False, "The ValueError was expected to be raised." |
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