From 4db99f4baf562c0515e887fd95793dfa2640b23d Mon Sep 17 00:00:00 2001 From: Dylan Lee Date: Thu, 14 May 2026 10:01:42 -0400 Subject: [PATCH] test: bypass unresponsive RISE API --- src/icefabric/helpers/rise/rise.py | 14 +++++++++++++- tests/app/test_rise_router.py | 15 ++++++++++----- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/icefabric/helpers/rise/rise.py b/src/icefabric/helpers/rise/rise.py index 6243485..b3f2d32 100644 --- a/src/icefabric/helpers/rise/rise.py +++ b/src/icefabric/helpers/rise/rise.py @@ -37,6 +37,8 @@ async def make_get_req_to_rise(full_url: str): the response is an error from RISE, the original code and message is returned as well. """ + import json + rise_response = {} async with httpx.AsyncClient() as client: try: @@ -44,11 +46,21 @@ async def make_get_req_to_rise(full_url: str): print(f"Making GET request to RISE (full URL): {full_url}") resp = await client.get(full_url, headers=RISE_HEADERS, timeout=15) resp.raise_for_status() - rise_response["detail"] = resp.json() + # Handle cases where API returns non-JSON response (e.g., HTML error page) + try: + rise_response["detail"] = resp.json() + except json.JSONDecodeError: + print("RISE API returned non-JSON response (likely API down)") + rise_response["status_code"] = 503 + rise_response["detail"] = "RISE API returned non-JSON response (service unavailable)" except httpx.TimeoutException as err: print(f"RISE API timed out: {err}") rise_response["status_code"] = 504 rise_response["detail"] = "RISE API request timed out" + except httpx.ReadTimeout as err: + print(f"RISE API read timed out: {err}") + rise_response["status_code"] = 504 + rise_response["detail"] = "RISE API request timed out" except httpx.HTTPStatusError as err: print(f"RISE API returned an HTTP error: {err}") rise_response["status_code"] = int(err.response.status_code) diff --git a/tests/app/test_rise_router.py b/tests/app/test_rise_router.py index 1cab52a..2e677dd 100644 --- a/tests/app/test_rise_router.py +++ b/tests/app/test_rise_router.py @@ -1,6 +1,8 @@ import json +import httpx import pytest +from starlette.testclient import TestClient from app.routers.rise_wrappers.router import EXT_RISE_BASE_URL, make_get_req_to_rise @@ -11,18 +13,21 @@ bad_ids = ["0", "0", "0", "0"] RISE_TIMEOUT_CODE = 504 +RISE_UNAVAILABLE_CODE = 503 -def _skip_if_rise_unavailable(response): +def _skip_if_rise_unavailable(response: httpx.Response) -> None: """Skip the test if RISE API is down or timing out.""" if response.status_code == RISE_TIMEOUT_CODE: pytest.skip("RISE API is unavailable (timeout)") + if response.status_code == RISE_UNAVAILABLE_CODE: + pytest.skip("RISE API is unavailable (service unavailable)") @pytest.mark.integration @pytest.mark.asyncio @pytest.mark.parametrize("resource_type,id", list(zip(resources, good_ids, strict=False))) -async def test_get_item_by_id_good(client, resource_type, id): +async def test_get_item_by_id_good(client: TestClient, resource_type: str, id: str) -> None: """Test all per-ID endpoints for IDs that exist""" response = client.get(f"/v1/rise/{resource_type}/{id}") _skip_if_rise_unavailable(response) @@ -34,7 +39,7 @@ async def test_get_item_by_id_good(client, resource_type, id): @pytest.mark.integration @pytest.mark.asyncio @pytest.mark.parametrize("resource_type,id", list(zip(resources, bad_ids, strict=False))) -async def test_get_item_by_id_bad(client, resource_type, id): +async def test_get_item_by_id_bad(client: TestClient, resource_type: str, id: str) -> None: """Test all per-ID endpoints for IDs that do not exist""" response = client.get(f"/v1/rise/{resource_type}/{id}") _skip_if_rise_unavailable(response) @@ -46,7 +51,7 @@ async def test_get_item_by_id_bad(client, resource_type, id): @pytest.mark.integration @pytest.mark.asyncio @pytest.mark.parametrize("resource_type", resources) -async def test_get_collection(client, resource_type): +async def test_get_collection(client: TestClient, resource_type: str) -> None: """Test every resource collection endpoint - all default parameters""" # TODO - remove skip once the RISE api/result endpoint is no longer timing out if resource_type == "result": @@ -61,7 +66,7 @@ async def test_get_collection(client, resource_type): @pytest.mark.integration @pytest.mark.asyncio @pytest.mark.parametrize("resource_type", resources) -async def test_get_collection_set_of_ids(client, resource_type): +async def test_get_collection_set_of_ids(client: TestClient, resource_type: str) -> None: """Test every resource collection endpoint with a set of three IDs""" # TODO - remove skip once the RISE api/result endpoint is no longer timing out if resource_type == "result":