Skip to content

Commit

Permalink
Fixed missing config dict error (in remote CI/CD) by mocking it, move…
Browse files Browse the repository at this point in the history
…d load_config into function, #45
  • Loading branch information
MarcoHuebner committed Sep 4, 2022
1 parent 40097f4 commit 2f7cdef
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/pygenesis/http_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from pygenesis.config import load_config
from pygenesis.custom_exceptions import DestatisStatusError

config = load_config()
logger = logging.getLogger(__name__)


Expand All @@ -26,6 +25,7 @@ def get_response_from_endpoint(
Returns:
requests.Response: the response from Destatis
"""
config = load_config()
url = f"{config['GENESIS API']['base_url']}{endpoint}/{method}"

params |= {
Expand Down
12 changes: 10 additions & 2 deletions tests/test_http_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,20 @@ def _generic_request_status(


@patch("requests.get")
def test_get_response_from_endpoint(mocker):
@patch("pygenesis.http_helper.load_config")
def test_get_response_from_endpoint(mock_config, mock_requests):
"""
Test once with generic API response, more detailed tests
of subfunctions and specific cases below.
"""
mocker.return_value = _generic_request_status()
mock_config.return_value = {
"GENESIS API": {
"base_url": "mocked_url",
"username": "JaneDoe",
"password": "password",
}
}
mock_requests.return_value = _generic_request_status()

get_response_from_endpoint("endpoint", "method", {})

Expand Down

0 comments on commit 2f7cdef

Please sign in to comment.