test_4_0_compatibility.py 950 B

123456789101112131415161718192021222324252627
  1. from django.core.checks import Error
  2. from django.core.checks.compatibility.django_4_0 import (
  3. check_csrf_trusted_origins,
  4. )
  5. from django.test import SimpleTestCase
  6. from django.test.utils import override_settings
  7. class CheckCSRFTrustedOrigins(SimpleTestCase):
  8. @override_settings(CSRF_TRUSTED_ORIGINS=['example.com'])
  9. def test_invalid_url(self):
  10. self.assertEqual(check_csrf_trusted_origins(None), [
  11. Error(
  12. 'As of Django 4.0, the values in the CSRF_TRUSTED_ORIGINS '
  13. 'setting must start with a scheme (usually http:// or '
  14. 'https://) but found example.com. See the release notes for '
  15. 'details.',
  16. id='4_0.E001',
  17. )
  18. ])
  19. @override_settings(
  20. CSRF_TRUSTED_ORIGINS=['http://example.com', 'https://example.com'],
  21. )
  22. def test_valid_urls(self):
  23. self.assertEqual(check_csrf_trusted_origins(None), [])