Skip to content

Commit 1fb2a04

Browse files
committed
Apply test config patch in api_calls tests
1 parent 81f3687 commit 1fb2a04

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/ghga_connector/config.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ async def set_runtime_config(client: httpx.AsyncClient):
119119
Raises:
120120
WellKnownValueNotFound: If one of the well-known values is not found in the
121121
response from the WKVS.
122+
BadResponseCodeError: If the status code returned is not 200
122123
ConnectionFailedError: If the request fails due to a timeout/connection problem
123124
RequestFailedError: If the request fails for any other reason
124125
"""
@@ -145,6 +146,7 @@ async def _get_wkvs_values(client: httpx.AsyncClient) -> dict[str, Any]:
145146
"""Retrieve a value from the well-known-value-service using the supplied client.
146147
147148
Raises:
149+
BadResponseCodeError: If the status code returned is not 200
148150
ConnectionFailedError: If the request fails due to a timeout/connection problem
149151
RequestFailedError: If the request fails for any other reason
150152
"""
@@ -156,4 +158,9 @@ async def _get_wkvs_values(client: httpx.AsyncClient) -> dict[str, Any]:
156158
exceptions.raise_if_connection_failed(request_error=request_error, url=url)
157159
raise exceptions.RequestFailedError(url=url) from request_error
158160

161+
if response.status_code != 200:
162+
raise exceptions.BadResponseCodeError(
163+
url=url, response_code=response.status_code
164+
)
165+
159166
return response.json()

tests/unit/test_api_calls.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
from contextlib import nullcontext
2222
from functools import partial
2323
from pathlib import Path
24-
from unittest.mock import Mock
24+
from unittest.mock import Mock, patch
2525

2626
import httpx
2727
import pytest
@@ -39,6 +39,7 @@
3939
from ghga_connector.core.uploading.structs import UploadStatus
4040
from ghga_connector.core.uploading.uploader import Uploader
4141
from tests.fixtures import set_runtime_test_config # noqa: F401
42+
from tests.fixtures.config import get_test_config
4243
from tests.fixtures.mock_api.app import (
4344
create_caching_headers,
4445
mock_external_calls, # noqa: F401
@@ -55,6 +56,16 @@
5556
]
5657

5758

59+
@pytest.fixture(scope="function", autouse=True)
60+
def apply_test_config():
61+
"""Apply default test config"""
62+
with (
63+
patch("ghga_connector.config.CONFIG", get_test_config()),
64+
patch("ghga_connector.cli.CONFIG", get_test_config()),
65+
):
66+
yield
67+
68+
5869
class RecordingClient(httpx.AsyncClient):
5970
"""An `AsyncClient` wrapper that records responses."""
6071

0 commit comments

Comments
 (0)