Report errors from CTS

If the service returns a status code indicating a user error, report
that and do not retry.

Signed-off-by: Lubomír Sedlář <lsedlar@redhat.com>
This commit is contained in:
Lubomír Sedlář 2022-11-23 10:26:28 +01:00
parent 12e3a46390
commit dd8c1002d4
2 changed files with 21 additions and 0 deletions

View file

@ -628,6 +628,7 @@ class ComposeTestCase(unittest.TestCase):
ci_copy = dict(self.ci_json)
ci_copy["header"]["version"] = "1.2"
mocked_response = mock.MagicMock()
mocked_response.status_code = 200
mocked_response.text = json.dumps(self.ci_json)
mocked_requests.post.return_value = mocked_response
@ -827,3 +828,17 @@ class RetryRequestTest(unittest.TestCase):
],
)
self.assertEqual(rv.status_code, 200)
@mock.patch("pungi.compose.requests")
def test_no_retry_on_client_error(self, mocked_requests):
mocked_requests.post.side_effect = [
mock.Mock(status_code=400, json=lambda: {"message": "You made a mistake"}),
]
url = "http://locahost/api/1/composes/"
with self.assertRaises(RuntimeError):
retry_request("post", url)
self.assertEqual(
mocked_requests.mock_calls,
[mock.call.post(url, json=None, auth=None)],
)