Skip to content

Commit

Permalink
fix: Contributor frontend 4 (#133)
Browse files Browse the repository at this point in the history
* fix: override default error handlers

* don't raise request exception

* fix: urls structure

* import url patterns

* correct number of args

* fix sort

* pylint ignore
  • Loading branch information
SKairinos authored Sep 16, 2024
1 parent 1fda2dc commit 373ef2d
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 5 deletions.
15 changes: 12 additions & 3 deletions codeforlife/tests/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,17 @@ class APIClient(_APIClient, t.Generic[RequestUser]):

_test_case: "APITestCase[RequestUser]"

def __init__(self, enforce_csrf_checks: bool = False, **defaults):
super().__init__(enforce_csrf_checks, **defaults)
def __init__(
self,
enforce_csrf_checks: bool = False,
raise_request_exception=False,
**defaults,
):
super().__init__(
enforce_csrf_checks,
raise_request_exception=raise_request_exception,
**defaults,
)

self.request_factory = APIRequestFactory(
self.get_request_user_class(),
Expand Down Expand Up @@ -329,7 +338,7 @@ def generic(
assert status_code_assertion(
status_code
), f"Unexpected status code: {status_code}." + (
"\nValidation errors:: "
"\nValidation errors: "
+ json.dumps(
# pylint: disable-next=no-member
response.json(), # type: ignore[attr-defined]
Expand Down
7 changes: 7 additions & 0 deletions codeforlife/urls/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"""
© Ocado Group
Created on 16/09/2024 at 15:23:05(+01:00).
"""

from .handlers import handler400, handler403, handler404, handler500
from .patterns import UrlPatterns, get_urlpatterns
23 changes: 23 additions & 0 deletions codeforlife/urls/handlers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""
© Ocado Group
Created on 16/09/2024 at 15:19:54(+01:00).
Custom error handlers which override django's default behavior to render a
template.
https://docs.djangoproject.com/en/3.2/ref/urls/#module-django.conf.urls
"""

from django.http import (
HttpResponseBadRequest,
HttpResponseForbidden,
HttpResponseNotFound,
HttpResponseServerError,
)

# pylint: disable=unnecessary-lambda-assignment
handler400 = lambda request, template: HttpResponseBadRequest()
handler403 = lambda request, template: HttpResponseForbidden()
handler404 = lambda request, template: HttpResponseNotFound()
handler500 = lambda request: HttpResponseServerError()
# pylint: enable=unnecessary-lambda-assignment
4 changes: 2 additions & 2 deletions codeforlife/urls.py → codeforlife/urls/patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
from django.urls import URLPattern, URLResolver, include, path, re_path
from rest_framework import status

from .settings import SERVICE_IS_ROOT, SERVICE_NAME
from .views import CsrfCookieView, LogoutView
from ..settings import SERVICE_IS_ROOT, SERVICE_NAME
from ..views import CsrfCookieView, LogoutView

UrlPatterns = t.List[t.Union[URLResolver, URLPattern]]

Expand Down

0 comments on commit 373ef2d

Please sign in to comment.