From f8c4dd2d64049b39659072360c35179c7f19aafb Mon Sep 17 00:00:00 2001 From: elkezza <47871727+elkezza@users.noreply.github.com> Date: Mon, 27 May 2024 21:34:23 +0200 Subject: [PATCH] using a proper API operation to simulate 5xx error --- tests/test_client.py | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/tests/test_client.py b/tests/test_client.py index 98d6b6b..a7f1583 100644 --- a/tests/test_client.py +++ b/tests/test_client.py @@ -56,21 +56,18 @@ def test_client_error_handling(requests_mock): assert "Client error 404" in str(e) assert '{"message":"Instance not found"}' in str(e) - # Mock a 500 server error + # Mock a 503 server error requests_mock.get( - "https://api-ch-gva-2.exoscale.com/v2/500_error", - status_code=500, - text="Internal Server Error", + "https://api-ch-gva-2.exoscale.com/v2/template", + status_code=503, + text='{"message":"Endpoint template temporarily unavailable"}', ) try: - response = client.session.get( - "https://api-ch-gva-2.exoscale.com/v2/500_error" - ) - response.raise_for_status() + client.list_templates() except ExoscaleAPIServerException as e: - assert "Server error 500" in str(e) + assert "Server error 503" in str(e) except Exception as e: - assert "500 Server Error" in str(e) + assert "503 Server Error" in str(e) if __name__ == "__main__":