diff options
author | 2024-08-15 00:58:46 +0100 | |
---|---|---|
committer | 2024-08-15 00:58:46 +0100 | |
commit | 0b44c86d12db36bba5cf74eaa045d9731b741b71 (patch) | |
tree | a602893eab3cbc23d0e65533956e85864cb5695e /pydis_site/apps | |
parent | Harden GitHub metadata fetch on homepage (diff) |
Add raise_for_status to MockResponse in repodata helper tests
Diffstat (limited to 'pydis_site/apps')
-rw-r--r-- | pydis_site/apps/home/tests/test_repodata_helpers.py | 10 |
1 files changed, 10 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 acf4a817..89514357 100644 --- a/pydis_site/apps/home/tests/test_repodata_helpers.py +++ b/pydis_site/apps/home/tests/test_repodata_helpers.py @@ -5,6 +5,7 @@ from unittest import mock from django.test import TestCase from django.utils import timezone +from httpx import HTTPStatusError from pydis_site.apps.home.models import RepositoryMetadata from pydis_site.apps.home.views import HomeView @@ -20,6 +21,15 @@ def mocked_requests_get(*args, **kwargs) -> "MockResponse": # noqa: F821 def json(self): return self.json_data + def raise_for_status(self): + if not 200 >= self.status_code < 400: + 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. + request=None, + response=self + ) + if args[0] == HomeView.github_api: json_path = Path(__file__).resolve().parent / "mock_github_api_response.json" with open(json_path) as json_file: |