Skip to content

Commit

Permalink
Add raise_for_status to MockResponse in repodata helper tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jb3 committed Aug 14, 2024
1 parent dfe9e9f commit 0b44c86
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions pydis_site/apps/home/tests/test_repodata_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

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
Expand All @@ -20,6 +21,15 @@ def __init__(self, json_data, status_code):
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:
Expand Down

0 comments on commit 0b44c86

Please sign in to comment.