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