Skip to content

Commit 5937066

Browse files
committed
Delete WKVSCaller module and update code
1 parent dcc26d4 commit 5937066

File tree

3 files changed

+35
-109
lines changed

3 files changed

+35
-109
lines changed

src/ghga_connector/core/api_calls/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,3 @@
1818
"""
1919

2020
from .utils import check_url, is_service_healthy # noqa: F401
21-
from .well_knowns import WKVSCaller # noqa: F401

src/ghga_connector/core/api_calls/well_knowns.py

Lines changed: 0 additions & 82 deletions
This file was deleted.

tests/unit/test_api_calls.py

Lines changed: 35 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,22 @@
2828
from pytest_httpx import HTTPXMock
2929

3030
from ghga_connector import exceptions
31+
from ghga_connector.config import (
32+
_get_wkvs_value,
33+
get_dcs_api_url,
34+
get_ghga_pubkey,
35+
get_ucs_api_url,
36+
get_wps_api_url,
37+
set_runtime_config,
38+
)
3139
from ghga_connector.core import WorkPackageAccessor, async_client
32-
from ghga_connector.core.api_calls.well_knowns import WKVSCaller
3340
from ghga_connector.core.uploading.structs import UploadStatus
3441
from ghga_connector.core.uploading.uploader import Uploader
3542
from tests.fixtures import set_runtime_test_config # noqa: F401
36-
from tests.fixtures.mock_api.app import create_caching_headers
43+
from tests.fixtures.mock_api.app import (
44+
create_caching_headers,
45+
mock_external_calls, # noqa: F401
46+
)
3747
from tests.fixtures.utils import mock_wps_token
3848

3949
pytestmark = [
@@ -305,29 +315,28 @@ async def test_get_wps_file_info(
305315
response = await work_package_accessor.get_package_files()
306316

307317

308-
# TODO: Get rid of wkvs caller and update this test
309-
async def test_wkvs_calls(httpx_mock: HTTPXMock):
310-
"""Test handling of responses for WKVS api calls"""
311-
wkvs_url = "https://127.0.0.1"
312-
318+
async def test_set_runtime_config(mock_external_calls): # noqa: F811
319+
"""Test set_runtime_config and related code"""
320+
# Make a list of the ctx var retrieval functions
321+
ctx_var_getter_fns = [
322+
get_dcs_api_url,
323+
get_ghga_pubkey,
324+
get_ucs_api_url,
325+
get_wps_api_url,
326+
]
313327
async with async_client() as client:
314-
wkvs_caller = WKVSCaller(client=client, wkvs_url=wkvs_url)
315-
316328
with pytest.raises(exceptions.WellKnownValueNotFound):
317-
httpx_mock.add_response(status_code=404)
318-
await wkvs_caller.get_server_pubkey()
319-
320-
with pytest.raises(KeyError):
321-
httpx_mock.add_response(status_code=200, json={})
322-
await wkvs_caller.get_server_pubkey()
323-
324-
# test each call to CYA
325-
for func, value_name in [
326-
(wkvs_caller.get_dcs_api_url, "dcs_api_url"),
327-
(wkvs_caller.get_server_pubkey, "crypt4gh_public_key"),
328-
(wkvs_caller.get_ucs_api_url, "ucs_api_url"),
329-
(wkvs_caller.get_wps_api_url, "wps_api_url"),
330-
]:
331-
httpx_mock.add_response(json={value_name: "dummy-value"})
332-
value = await func()
333-
assert value == "dummy-value"
329+
_ = await _get_wkvs_value(client, value_name="bogus")
330+
331+
# Verify that all the context vars are empty before calling config setup
332+
for func in ctx_var_getter_fns:
333+
with pytest.raises(ValueError):
334+
_ = func()
335+
336+
# Set up runtime config
337+
async with set_runtime_config(client):
338+
# verify values are now set (from mock api)
339+
for func in ctx_var_getter_fns:
340+
value = func()
341+
assert isinstance(value, str)
342+
assert len(value) > 0

0 commit comments

Comments
 (0)