Coverage for benefits/urls.py: 71%

27 statements  

« prev     ^ index     » next       coverage.py v7.6.10, created at 2025-01-29 21:21 +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] 

32 

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

34 # serve user-uploaded media files 

35 # 

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

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

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

39 prefix = settings.MEDIA_URL 

40 urlpatterns.extend( 

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

42 ) 

43 

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

45 # based on 

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

47 

48 def trigger_error(request): 

49 raise RuntimeError("Test error") 

50 

51 urlpatterns.append(path("error/", trigger_error)) 

52 

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

54 # this "secret" does not contain sensitive information 

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

56 

57 def test_secret(request): 

58 from benefits.secrets import get_secret_by_name 

59 

60 return HttpResponse(get_secret_by_name("testsecret")) 

61 

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

63 

64logger.debug("Register admin urls") 

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

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