2
0

test_context_processor.py 579 B

1234567891011121314
  1. from django.http import HttpRequest
  2. from django.middleware.csrf import _compare_masked_tokens as equivalent_tokens
  3. from django.template.context_processors import csrf
  4. from django.test import SimpleTestCase
  5. class TestContextProcessor(SimpleTestCase):
  6. def test_force_token_to_string(self):
  7. request = HttpRequest()
  8. test_token = '1bcdefghij2bcdefghij3bcdefghij4bcdefghij5bcdefghij6bcdefghijABCD'
  9. request.META['CSRF_COOKIE'] = test_token
  10. token = csrf(request).get('csrf_token')
  11. self.assertTrue(equivalent_tokens(str(token), test_token))