Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

APPEND_SLASH enabled and added logic to append slash #498

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion registrar/apps/api/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from django.conf import settings
from django.urls import reverse

from registrar.helpers import append_slash

def build_absolute_api_url(url_name, **kwargs):
"""
Expand All @@ -17,7 +18,7 @@ def build_absolute_api_url(url_name, **kwargs):

Returns: str
"""
return to_absolute_api_url(reverse(url_name, kwargs=kwargs))
return to_absolute_api_url(append_slash(reverse(url_name, kwargs=kwargs)))


def to_absolute_api_url(path, *more_paths):
Expand Down
3 changes: 2 additions & 1 deletion registrar/apps/api/v1/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import ddt
import moto
import requests
from registrar.helpers import append_slash
import responses
from celery import shared_task
from django.conf import settings
Expand Down Expand Up @@ -1798,7 +1799,7 @@ def get_url(self, program_key=None, course_id=None):
'program_key': program_key or self.cs_program.key,
'course_id': course_id or self.course_id,
}
return reverse('api:v1:program-course-enrollment', kwargs=kwargs)
return append_slash(reverse('api:v1:program-course-enrollment', kwargs=kwargs))

def mock_course_enrollments_response(self, method, expected_response, response_code=200):
self.mock_api_response(self.lms_request_url, expected_response, method=method, response_code=response_code)
Expand Down
5 changes: 3 additions & 2 deletions registrar/apps/core/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django.test.utils import override_settings
from django.urls import reverse

from registrar.helpers import append_slash
from ..constants import Status


Expand All @@ -29,7 +30,7 @@ def test_database_outage(self):

def _assert_health(self, status_code, overall_status, database_status):
"""Verify that the response matches expectations."""
response = self.client.get(reverse('health'))
response = self.client.get(append_slash(reverse('health')))
self.assertEqual(response.status_code, status_code)
self.assertEqual(response['content-type'], 'application/json')

Expand All @@ -45,7 +46,7 @@ def _assert_health(self, status_code, overall_status, database_status):

class AutoAuthTests(TestCase):
""" Auto Auth view tests. """
AUTO_AUTH_PATH = reverse('auto_auth')
AUTO_AUTH_PATH = append_slash(reverse('auto_auth'))

@override_settings(ENABLE_AUTO_AUTH=False)
def test_setting_disabled(self):
Expand Down
8 changes: 8 additions & 0 deletions registrar/helpers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.conf import settings



def append_slash(complete_url: str) -> str:
if settings.APPEND_SLASH and not complete_url.endswith('/'):
complete_url = complete_url + '/' # Required for consistency
return complete_url
2 changes: 1 addition & 1 deletion registrar/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@


ROOT_URLCONF = 'registrar.urls'
APPEND_SLASH = False
APPEND_SLASH = True

# Python dotted path to the WSGI application used by Django's runserver.
WSGI_APPLICATION = 'registrar.wsgi.application'
Expand Down