|
1 | | -from django.test import TestCase |
| 1 | +from django.test import Client, TestCase |
2 | 2 | from django.test.utils import override_settings |
3 | 3 | from django.urls import reverse |
4 | 4 |
|
| 5 | +import pytest |
| 6 | +from pytest_django.asserts import assertRedirects |
| 7 | + |
5 | 8 | from cookie_consent.models import ( |
6 | 9 | ACTION_ACCEPTED, |
7 | 10 | ACTION_DECLINED, |
|
11 | 14 | ) |
12 | 15 |
|
13 | 16 |
|
14 | | -class CookieGroupBaseProcessViewTests(TestCase): |
15 | | - def test_get_success_url(self): |
16 | | - """ |
17 | | - If user adds a 'next' as URL parameter it should, |
18 | | - redirect to the value of 'next' |
19 | | - """ |
20 | | - expected_url = reverse("test_page") |
21 | | - url = "{}?next={}".format(reverse("cookie_consent_accept_all"), expected_url) |
22 | | - response = self.client.post(url, follow=True) |
23 | | - self.assertRedirects(response, expected_url) |
24 | | - |
25 | | - def test_no_open_redirects(self): |
26 | | - url = "{}?next=https://evil.com".format(reverse("cookie_consent_accept_all")) |
27 | | - response = self.client.post(url, follow=True) |
28 | | - self.assertEqual(response.status_code, 400) # result of SupiciousOperation |
| 17 | +@pytest.mark.django_db |
| 18 | +def test_processing_get_success_url(client: Client): |
| 19 | + """ |
| 20 | + If user adds a 'next' as URL parameter it should, |
| 21 | + redirect to the value of 'next' |
| 22 | + """ |
| 23 | + expected_url = reverse("test_page") |
| 24 | + url = "{}?next={}".format(reverse("cookie_consent_accept_all"), expected_url) |
| 25 | + |
| 26 | + response = client.post(url, follow=True) |
| 27 | + |
| 28 | + assertRedirects(response, expected_url) |
| 29 | + |
| 30 | + |
| 31 | +@pytest.mark.django_db |
| 32 | +def test_processing_no_open_redirects(client: Client): |
| 33 | + url = "{}?next=https://evil.com".format(reverse("cookie_consent_accept_all")) |
| 34 | + |
| 35 | + response = client.post(url, follow=True) |
| 36 | + |
| 37 | + assert response.status_code == 400 # result of SupiciousOperation |
| 38 | + |
| 39 | + |
| 40 | +@pytest.mark.django_db |
| 41 | +def test_alternative_redirect_fallback(client: Client, settings): |
| 42 | + settings.COOKIE_CONSENT_SUCCESS_URL = "/alternative" |
| 43 | + |
| 44 | + response = client.post(reverse("cookie_consent_accept_all"), follow=False) |
| 45 | + |
| 46 | + assertRedirects(response, "/alternative", fetch_redirect_response=False) |
29 | 47 |
|
30 | 48 |
|
31 | 49 | class IntegrationTest(TestCase): |
|
0 commit comments