Skip to content

Commit

Permalink
Add tests for new raise_for_status test shim helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
jb3 committed Aug 15, 2024
1 parent 0b44c86 commit 325fda3
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pydis_site/apps/home/tests/test_repodata_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def raise_for_status(self):
raise HTTPStatusError(
# NOTE: We only consume the response status code when working with this helper.
# If we ever need the request, this shim needs to be updated.
f"Received non-200/300 status code when performing request: HTTP {self.status_code}",
request=None,
response=self
)
Expand Down Expand Up @@ -108,6 +109,14 @@ def test_mocked_requests_get(self, mock_get: mock.MagicMock):
self.assertIsNotNone(success_data.json_data)
self.assertIsNone(fail_data.json_data)

@mock.patch('httpx.get', side_effect=mocked_requests_get)
def test_mocked_requests_raise_status(self, mock_get: mock.MagicMock):
"""Tests if our mocked_requests_get raises an exception for bad statuses."""
fail_data = mock_get("failtest")

with self.assertRaises(HTTPStatusError):
fail_data.raise_for_status()

@mock.patch('httpx.get')
def test_falls_back_to_database_on_error(self, mock_get: mock.MagicMock):
"""Tests that fallback to the database is performed when we get garbage back."""
Expand Down

0 comments on commit 325fda3

Please sign in to comment.