-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#2648] handle legacy case detail URLs with redirect
- Loading branch information
1 parent
1edaef7
commit 705b045
Showing
4 changed files
with
128 additions
and
1 deletion.
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
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
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
70 changes: 70 additions & 0 deletions
70
src/open_inwoner/openzaak/tests/test_case_detail_redirects.py
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,70 @@ | ||
from django.contrib.messages import get_messages | ||
from django.test import TestCase, override_settings | ||
from django.urls import reverse | ||
|
||
from open_inwoner.openzaak.tests.factories import ZGWApiGroupConfigFactory | ||
|
||
|
||
@override_settings( | ||
ROOT_URLCONF="open_inwoner.cms.tests.urls", | ||
) | ||
class LegacyCaseDetailUrlRedirectTest(TestCase): | ||
def setUp(self): | ||
self.url_patterns = [ | ||
"case_detail", | ||
] | ||
|
||
def test_legacy_url_redirects_to_only_api_group_prefix(self): | ||
first = ZGWApiGroupConfigFactory() | ||
|
||
object_id = "test_object_id" | ||
legacy_handler_url = reverse( | ||
"cases:legacy_case_detail", | ||
kwargs={"object_id": object_id}, | ||
) | ||
target_url = reverse( | ||
"cases:case_detail", | ||
kwargs={"api_group_id": first.id, "object_id": object_id}, | ||
) | ||
|
||
response = self.client.get(legacy_handler_url) | ||
self.assertEqual(response.status_code, 302) | ||
self.assertEqual(response["Location"], target_url) | ||
|
||
def test_legacy_url_redirects_to_case_list_if_multiple_api_groups(self): | ||
first = ZGWApiGroupConfigFactory() | ||
second = ZGWApiGroupConfigFactory() # noqa | ||
|
||
object_id = "test_object_id" | ||
legacy_handler_url = reverse( | ||
"cases:legacy_case_detail", | ||
kwargs={"object_id": object_id}, | ||
) | ||
target_url = reverse("cases:index") | ||
|
||
response = self.client.get(legacy_handler_url) | ||
messages = [str(m) for m in get_messages(response.wsgi_request)] | ||
|
||
self.assertEqual(response.status_code, 302) | ||
self.assertEqual(response["Location"], reverse("cases:index")) | ||
self.assertEqual( | ||
messages, | ||
[ | ||
"The link you've used has expired. Please find the case you are looking for below." | ||
], | ||
) | ||
|
||
def test_legacy_url_redirect_returns_404_on_missing_api_groups(self): | ||
object_id = "test_object_id" | ||
legacy_handler_url = reverse( | ||
"cases:legacy_case_detail", | ||
kwargs={"object_id": object_id}, | ||
) | ||
|
||
legacy_handler_url = reverse( | ||
"cases:legacy_case_detail", | ||
kwargs={"object_id": object_id}, | ||
) | ||
|
||
response = self.client.get(legacy_handler_url) | ||
self.assertEqual(response.status_code, 404) |