|
28 | 28 | from pytest_httpx import HTTPXMock |
29 | 29 |
|
30 | 30 | 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 | +) |
31 | 39 | from ghga_connector.core import WorkPackageAccessor, async_client |
32 | | -from ghga_connector.core.api_calls.well_knowns import WKVSCaller |
33 | 40 | from ghga_connector.core.uploading.structs import UploadStatus |
34 | 41 | from ghga_connector.core.uploading.uploader import Uploader |
35 | 42 | 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 | +) |
37 | 47 | from tests.fixtures.utils import mock_wps_token |
38 | 48 |
|
39 | 49 | pytestmark = [ |
@@ -305,29 +315,28 @@ async def test_get_wps_file_info( |
305 | 315 | response = await work_package_accessor.get_package_files() |
306 | 316 |
|
307 | 317 |
|
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 | + ] |
313 | 327 | async with async_client() as client: |
314 | | - wkvs_caller = WKVSCaller(client=client, wkvs_url=wkvs_url) |
315 | | - |
316 | 328 | 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