mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-07-02 17:23:32 +02:00
Add a unit test for new template tag
This commit is contained in:
parent
400232a10f
commit
135192fd9f
3 changed files with 37 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
31
src/registrar/tests/test_templatetags.py
Normal file
31
src/registrar/tests/test_templatetags.py
Normal file
|
@ -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)
|
Loading…
Add table
Add a link
Reference in a new issue