diff options
author | 2024-08-15 01:03:52 +0100 | |
---|---|---|
committer | 2024-08-15 01:03:52 +0100 | |
commit | 325fda3dddf867a1d90a44ed637fc8f1ab2d0ca4 (patch) | |
tree | ebd8add5b406a1d428eb00793999013822f5ccd7 | |
parent | Add raise_for_status to MockResponse in repodata helper tests (diff) |
Add tests for new raise_for_status test shim helpers
-rw-r--r-- | pydis_site/apps/home/tests/test_repodata_helpers.py | 9 |
1 files changed, 9 insertions, 0 deletions
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.""" |