-
Notifications
You must be signed in to change notification settings - Fork 153
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
775d84f
commit 9eb4684
Showing
1 changed file
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/") |