Coverage for benefits/urls.py: 71%

27 statements  

« prev     ^ index     » next       coverage.py v7.9.1, created at 2025-06-30 22:10 +0000

1""" 

2benefits URL Configuration 

3 

4The `urlpatterns` list routes URLs to views. For more information please see: 

5 https://docs.djangoproject.com/en/5.0/topics/http/urls/ 

6""" 

7 

8import logging 

9import re 

10 

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 

16 

17logger = logging.getLogger(__name__) 

18 

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" 

23 

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 path("switchio/", include("benefits.enrollment_switchio.urls")), 

33] 

34 

35if settings.RUNTIME_ENVIRONMENT() == settings.RUNTIME_ENVS.LOCAL: 35 ↛ 46line 35 didn't jump to line 46 because the condition on line 35 was always true

36 # serve user-uploaded media files 

37 # 

38 # the helper function `django.conf.urls.static.static` mentioned in 

39 # https://docs.djangoproject.com/en/5.1/howto/static-files/#serving-files-uploaded-by-a-user-during-development 

40 # only works when settings.DEBUG = True, so here we add the URL pattern ourselves so it works regardless of DEBUG. 

41 prefix = settings.MEDIA_URL 

42 urlpatterns.extend( 

43 [re_path(r"^%s(?P<path>.*)$" % re.escape(prefix.lstrip("/")), serve, {"document_root": settings.MEDIA_ROOT})] 

44 ) 

45 

46if settings.DEBUG: 46 ↛ 50line 46 didn't jump to line 50 because the condition on line 46 was never true

47 # based on 

48 # https://docs.sentry.io/platforms/python/guides/django/#verify 

49 

50 def trigger_error(request): 

51 raise RuntimeError("Test error") 

52 

53 urlpatterns.append(path("testerror/", trigger_error)) 

54 

55 # simple route to read a pre-defined "secret" 

56 # this "secret" does not contain sensitive information 

57 # and is only configured in the dev environment for testing/debugging 

58 

59 def test_secret(request): 

60 from benefits.secrets import get_secret_by_name 

61 

62 return HttpResponse(get_secret_by_name("testsecret")) 

63 

64 urlpatterns.append(path("testsecret/", test_secret)) 

65 

66logger.debug("Register admin urls") 

67urlpatterns.append(path("admin/", admin.site.urls)) 

68urlpatterns.append(path("google_sso/", include("django_google_sso.urls", namespace="django_google_sso")))