diff --git a/src/docker-compose.yml b/src/docker-compose.yml index 8b1111868..82642bc93 100644 --- a/src/docker-compose.yml +++ b/src/docker-compose.yml @@ -28,7 +28,7 @@ services: # Tell Django where it is being hosted - DJANGO_BASE_URL=http://localhost:8080 # Public site URL link - - GETGOV_PUBLIC_SITE_URL="https://beta.get.gov" + - GETGOV_PUBLIC_SITE_URL=https://beta.get.gov # Set a username for accessing the registry - REGISTRY_CL_ID=nothing # Set a password for accessing the registry diff --git a/src/registrar/templatetags/url_helpers.py b/src/registrar/templatetags/url_helpers.py index 7662a42d8..096d6f2f6 100644 --- a/src/registrar/templatetags/url_helpers.py +++ b/src/registrar/templatetags/url_helpers.py @@ -29,5 +29,9 @@ def public_site_url(url_path): variable. """ base_url = settings.GETGOV_PUBLIC_SITE_URL - public_url = urljoin(base_url, url_path) + # join the two halves with a single slash + public_url ="/".join([ + base_url.rstrip("/"), + url_path.lstrip("/") + ]) return public_url diff --git a/src/registrar/tests/test_templatetags.py b/src/registrar/tests/test_templatetags.py new file mode 100644 index 000000000..10a174be0 --- /dev/null +++ b/src/registrar/tests/test_templatetags.py @@ -0,0 +1,31 @@ +"""Test template tags.""" + +from django.conf import settings +from django.test import TestCase +from django.template import Context, Template + +class TestTemplateTags(TestCase): + + def _render_template(self, string, context=None): + """Helper method to render a template given as a string. + + Originally from https://stackoverflow.com/a/1690879 + """ + context = context or {} + context = Context(context) + return Template(string).render(context) + + def test_public_site_url(self): + result = self._render_template( + "{% load url_helpers %}{% public_site_url 'directory/page' %}" + ) + self.assertTrue(result.startswith(settings.GETGOV_PUBLIC_SITE_URL)) + self.assertTrue(result.endswith("/directory/page")) + + def test_public_site_url_leading_slash(self): + result = self._render_template( + "{% load url_helpers %}{% public_site_url '/directory/page' %}" + ) + self.assertTrue(result.startswith(settings.GETGOV_PUBLIC_SITE_URL)) + # slash-slash host slash directory slash page + self.assertEqual(result.count("/"), 4)