From 325fda3dddf867a1d90a44ed637fc8f1ab2d0ca4 Mon Sep 17 00:00:00 2001 From: Joe Banks Date: Thu, 15 Aug 2024 01:03:52 +0100 Subject: Add tests for new raise_for_status test shim helpers --- pydis_site/apps/home/tests/test_repodata_helpers.py | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'pydis_site') diff --git a/pydis_site/apps/home/tests/test_repodata_helpers.py b/pydis_site/apps/home/tests/test_repodata_helpers.py index 89514357..6715444b 100644 --- a/pydis_site/apps/home/tests/test_repodata_helpers.py +++ b/pydis_site/apps/home/tests/test_repodata_helpers.py @@ -26,6 +26,7 @@ def mocked_requests_get(*args, **kwargs) -> "MockResponse": # noqa: F821 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 ) @@ -108,6 +109,14 @@ class TestRepositoryMetadataHelpers(TestCase): 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.""" -- cgit v1.2.3