Skip to content

Commit

Permalink
fix: urls structure
Browse files Browse the repository at this point in the history
  • Loading branch information
SKairinos committed Sep 16, 2024
1 parent 16aa0b3 commit a403e4f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 18 deletions.
2 changes: 1 addition & 1 deletion codeforlife/tests/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,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 get_urlpatterns
21 changes: 21 additions & 0 deletions codeforlife/urls/handlers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"""
© 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,
)

handler400 = lambda request: HttpResponseBadRequest()
handler403 = lambda request: HttpResponseForbidden()
handler404 = lambda request: HttpResponseNotFound()
handler500 = lambda request: HttpResponseServerError()
20 changes: 3 additions & 17 deletions codeforlife/urls.py → codeforlife/urls/patterns.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,12 @@
import typing as t

from django.contrib import admin
from django.http import (
HttpResponse,
HttpResponseBadRequest,
HttpResponseForbidden,
HttpResponseNotFound,
HttpResponseServerError,
)
from django.http import HttpResponse
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 Expand Up @@ -99,11 +93,3 @@ def get_urlpatterns(
name="service-not-found",
),
]


# Error handlers.
# https://docs.djangoproject.com/en/3.2/ref/urls/#module-django.conf.urls
handler400 = lambda request: HttpResponseBadRequest()
handler403 = lambda request: HttpResponseForbidden()
handler404 = lambda request: HttpResponseNotFound()
handler500 = lambda request: HttpResponseServerError()

0 comments on commit a403e4f

Please sign in to comment.