Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jhonatan-lopes committed Feb 22, 2024
1 parent 775d84f commit 9eb4684
Showing 1 changed file with 44 additions and 0 deletions.
44 changes: 44 additions & 0 deletions network-api/networkapi/wagtailpages/tests/test_views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
from django.test import RequestFactory, SimpleTestCase

from networkapi.wagtailpages.views import localized_redirect


class LocalizedRedirectTests(SimpleTestCase):
def setUp(self):
self.factory = RequestFactory()

def test_redirect_with_subpath_and_query_string(self):
# Create a mock request object
request = self.factory.get("/destination/")
request.LANGUAGE_CODE = "en"
request.META = {"QUERY_STRING": "param=value"}

# Call the localized_redirect function
result = localized_redirect(request, "subpath", "destination")

# Assert that the redirect URL is correct
self.assertEqual(result.url, "/en/destination/subpath?param=value")

def test_redirect_with_empty_subpath_and_query_string(self):
# Create a mock request object
request = self.factory.get("/destination/")
request.LANGUAGE_CODE = "en"
request.META = {"QUERY_STRING": ""}

# Call the localized_redirect function
result = localized_redirect(request, "", "destination")

# Assert that the redirect URL is correct
self.assertEqual(result.url, "/en/destination/")

def test_redirect_with_active_language(self):
# Create a mock request object
request = self.factory.get("/en/destination/")
request.LANGUAGE_CODE = "fr"
request.META = {"QUERY_STRING": ""}

# Call the localized_redirect function
result = localized_redirect(request, "", "destination")

# Assert that the redirect URL is correct
self.assertEqual(result.url, "/fr/destination/")

0 comments on commit 9eb4684

Please sign in to comment.