Coverage for benefits/urls.py: 71%
27 statements
« prev ^ index » next coverage.py v7.8.2, created at 2025-06-06 20:07 +0000
« prev ^ index » next coverage.py v7.8.2, created at 2025-06-06 20:07 +0000
1"""
2benefits URL Configuration
4The `urlpatterns` list routes URLs to views. For more information please see:
5 https://docs.djangoproject.com/en/5.0/topics/http/urls/
6"""
8import logging
9import re
11from django.conf import settings
12from django.contrib import admin
13from django.http import HttpResponse
14from django.urls import include, path, re_path
15from django.views.static import serve
17logger = logging.getLogger(__name__)
19handler400 = "benefits.core.views.bad_request"
20handler403 = "benefits.core.views.bad_request"
21handler404 = "benefits.core.views.page_not_found"
22handler500 = "benefits.core.views.server_error"
24urlpatterns = [
25 path("", include("benefits.core.urls")),
26 path("eligibility/", include("benefits.eligibility.urls")),
27 path("enrollment/", include("benefits.enrollment.urls")),
28 path("i18n/", include("django.conf.urls.i18n")),
29 path("oauth/", include("benefits.oauth.urls")),
30 path("in_person/", include("benefits.in_person.urls")),
31 path("littlepay/", include("benefits.enrollment_littlepay.urls")),
32]
34if settings.RUNTIME_ENVIRONMENT() == settings.RUNTIME_ENVS.LOCAL: 34 ↛ 45line 34 didn't jump to line 45 because the condition on line 34 was always true
35 # serve user-uploaded media files
36 #
37 # the helper function `django.conf.urls.static.static` mentioned in
38 # https://docs.djangoproject.com/en/5.1/howto/static-files/#serving-files-uploaded-by-a-user-during-development
39 # only works when settings.DEBUG = True, so here we add the URL pattern ourselves so it works regardless of DEBUG.
40 prefix = settings.MEDIA_URL
41 urlpatterns.extend(
42 [re_path(r"^%s(?P<path>.*)$" % re.escape(prefix.lstrip("/")), serve, {"document_root": settings.MEDIA_ROOT})]
43 )
45if settings.DEBUG: 45 ↛ 49line 45 didn't jump to line 49 because the condition on line 45 was never true
46 # based on
47 # https://docs.sentry.io/platforms/python/guides/django/#verify
49 def trigger_error(request):
50 raise RuntimeError("Test error")
52 urlpatterns.append(path("testerror/", trigger_error))
54 # simple route to read a pre-defined "secret"
55 # this "secret" does not contain sensitive information
56 # and is only configured in the dev environment for testing/debugging
58 def test_secret(request):
59 from benefits.secrets import get_secret_by_name
61 return HttpResponse(get_secret_by_name("testsecret"))
63 urlpatterns.append(path("testsecret/", test_secret))
65logger.debug("Register admin urls")
66urlpatterns.append(path("admin/", admin.site.urls))
67urlpatterns.append(path("google_sso/", include("django_google_sso.urls", namespace="django_google_sso")))