Skip to content

Commit

Permalink
Add tests for snippet list view redirect
Browse files Browse the repository at this point in the history
  • Loading branch information
jams2 committed Nov 23, 2023
1 parent 5836520 commit 92b960d
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion tests/test_views.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from django.contrib.messages import get_messages
from django.test import TestCase
from django.test import TestCase, override_settings
from django.urls import reverse

from tests.models import Advert
Expand Down Expand Up @@ -87,3 +87,25 @@ def test_airtable_message_on_instance_delete(self):
self.assertEqual(len(messages), 2)
self.assertIn('Advertisement 'Wow brand new?!' deleted', messages[0].message)
self.assertIn('Airtable record deleted', messages[1].message)

def test_snippet_list_redirect(self):
airtable_import_url = reverse("airtable_import_listing")
params = [
# DEBUG, next URL, expected redirect
(True, "http://testserver/redirect/", "http://testserver/redirect/"),
(True, "http://not-allowed-host/redirect/", airtable_import_url),
(False, "https://testserver/redirect/", "https://testserver/redirect/"),
(False, "http://testserver/redirect/", airtable_import_url),
(False, "https://not-allowed-host/redirect/", airtable_import_url),
]
for debug, next_url, expected_location in params:
with self.subTest(
debug=debug, next_url=next_url, expected_location=expected_location
):
with override_settings(DEBUG=debug):
response = self.client.post(
airtable_import_url,
{"model": "Advert", "next": next_url},
secure=next_url.startswith("https"),
)
self.assertEqual(response.url, expected_location)

0 comments on commit 92b960d

Please sign in to comment.