Skip to content

Commit b96fef2

Browse files
mwdd146980claude
andauthored
Fix unreachable service check assertions in cloud_foundry_api oauth error tests (DataDog#24282)
Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent d2fbda9 commit b96fef2

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

cloud_foundry_api/tests/test_cloud_foundry_api.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -283,9 +283,10 @@ def test_get_oauth_token_errors(_, __, ___, aggregator, instance):
283283
check = CloudFoundryApiCheck('cloud_foundry_api', {}, [instance])
284284
check._http = None # initialize the _http attribute for mocking
285285

286-
with mock.patch.object(check, "_http") as http_mock, pytest.raises(RequestException):
286+
with mock.patch.object(check, "_http") as http_mock:
287287
http_mock.get.side_effect = RequestException()
288-
check.get_oauth_token()
288+
with pytest.raises(RequestException):
289+
check.get_oauth_token()
289290
aggregator.assert_service_check(
290291
name="cloud_foundry_api.uaa.can_authenticate",
291292
status=CloudFoundryApiCheck.CRITICAL,
@@ -294,9 +295,10 @@ def test_get_oauth_token_errors(_, __, ___, aggregator, instance):
294295
)
295296
aggregator.reset()
296297

297-
with mock.patch.object(check, "_http") as http_mock, pytest.raises(HTTPError):
298+
with mock.patch.object(check, "_http") as http_mock:
298299
http_mock.get.return_value = mock.MagicMock(raise_for_status=mock.MagicMock(side_effect=HTTPError()))
299-
check.get_oauth_token()
300+
with pytest.raises(HTTPError):
301+
check.get_oauth_token()
300302
aggregator.assert_service_check(
301303
name="cloud_foundry_api.uaa.can_authenticate",
302304
status=CloudFoundryApiCheck.CRITICAL,
@@ -305,9 +307,10 @@ def test_get_oauth_token_errors(_, __, ___, aggregator, instance):
305307
)
306308
aggregator.reset()
307309

308-
with mock.patch.object(check, "_http") as http_mock, pytest.raises(ValueError):
310+
with mock.patch.object(check, "_http") as http_mock:
309311
http_mock.get.return_value = mock.MagicMock(json=mock.MagicMock(side_effect=ValueError()))
310-
check.get_oauth_token()
312+
with pytest.raises(ValueError):
313+
check.get_oauth_token()
311314
aggregator.assert_service_check(
312315
name="cloud_foundry_api.uaa.can_authenticate",
313316
status=CloudFoundryApiCheck.CRITICAL,

0 commit comments

Comments
 (0)