Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 9 additions & 6 deletions cloud_foundry_api/tests/test_cloud_foundry_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -283,9 +283,10 @@ def test_get_oauth_token_errors(_, __, ___, aggregator, instance):
check = CloudFoundryApiCheck('cloud_foundry_api', {}, [instance])
check._http = None # initialize the _http attribute for mocking

with mock.patch.object(check, "_http") as http_mock, pytest.raises(RequestException):
with mock.patch.object(check, "_http") as http_mock:
http_mock.get.side_effect = RequestException()
check.get_oauth_token()
with pytest.raises(RequestException):
check.get_oauth_token()
aggregator.assert_service_check(
name="cloud_foundry_api.uaa.can_authenticate",
status=CloudFoundryApiCheck.CRITICAL,
Expand All @@ -294,9 +295,10 @@ def test_get_oauth_token_errors(_, __, ___, aggregator, instance):
)
aggregator.reset()

with mock.patch.object(check, "_http") as http_mock, pytest.raises(HTTPError):
with mock.patch.object(check, "_http") as http_mock:
http_mock.get.return_value = mock.MagicMock(raise_for_status=mock.MagicMock(side_effect=HTTPError()))
check.get_oauth_token()
with pytest.raises(HTTPError):
check.get_oauth_token()
aggregator.assert_service_check(
name="cloud_foundry_api.uaa.can_authenticate",
status=CloudFoundryApiCheck.CRITICAL,
Expand All @@ -305,9 +307,10 @@ def test_get_oauth_token_errors(_, __, ___, aggregator, instance):
)
aggregator.reset()

with mock.patch.object(check, "_http") as http_mock, pytest.raises(ValueError):
with mock.patch.object(check, "_http") as http_mock:
http_mock.get.return_value = mock.MagicMock(json=mock.MagicMock(side_effect=ValueError()))
check.get_oauth_token()
with pytest.raises(ValueError):
check.get_oauth_token()
aggregator.assert_service_check(
name="cloud_foundry_api.uaa.can_authenticate",
status=CloudFoundryApiCheck.CRITICAL,
Expand Down
Loading