mirror of
https://github.com/wassname/Open-Assistant.git
synced 2026-06-27 16:10:30 +08:00
test: add test for unhandled api error
This commit is contained in:
@@ -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={})
|
||||
|
||||
Reference in New Issue
Block a user