test: add test for unhandled api error

This commit is contained in:
Jack Michaud
2023-01-02 21:06:00 -05:00
parent f66ad30c53
commit 3dcfe7014e
2 changed files with 21 additions and 1 deletions
+1 -1
View File
@@ -70,7 +70,7 @@ class OasstApiClient:
if response.status >= 300:
data = await response.json()
try:
oasst_error = protocol_schema.OasstErrorResponse(**data)
oasst_error = protocol_schema.OasstErrorResponse(**(data or {}))
raise OasstError(
error_code=oasst_error.error_code,
message=oasst_error.message,
@@ -106,3 +106,23 @@ async def test_can_handle_oasst_error_from_api(
with pytest.raises(OasstError):
await oasst_api_client_fake_http.post("/some-path", data={})
@pytest.mark.asyncio
async def test_can_handle_unknown_error_from_api(
oasst_api_client_fake_http: OasstApiClient,
mock_http_session: MockClientSession,
):
response_body = "Internal Server Error"
status_code = 500
mock_http_session.set_response(
mock.AsyncMock(
status=status_code,
text=mock.AsyncMock(return_value=response_body),
json=mock.AsyncMock(return_value=None),
)
)
with pytest.raises(OasstError):
await oasst_api_client_fake_http.post("/some-path", data={})