2019-02-19 14:15:03 +03:00
|
|
|
import re
|
|
|
|
|
2018-05-11 09:50:08 +03:00
|
|
|
from django.shortcuts import render
|
|
|
|
|
|
|
|
|
|
|
|
def test_base_template_with_no_context():
|
|
|
|
# base.html should be renderable with no context,
|
|
|
|
# so it can be easily extended.
|
2019-02-19 14:15:03 +03:00
|
|
|
result = render({}, 'rest_framework/base.html')
|
|
|
|
# note that this response will not include a valid CSRF token
|
2019-05-01 08:49:17 +03:00
|
|
|
assert re.search(r'\bcsrfToken: ""', result.content.decode())
|
2021-03-16 16:25:21 +03:00
|
|
|
|
|
|
|
|
|
|
|
def test_base_template_with_simple_context():
|
|
|
|
context = {'request': True, 'csrf_token': 'TOKEN'}
|
|
|
|
result = render({}, 'rest_framework/base.html', context=context)
|
|
|
|
# note that response will STILL not include a CSRF token
|
|
|
|
assert re.search(r'\bcsrfToken: ""', result.content.decode())
|
|
|
|
|
|
|
|
|
|
|
|
def test_base_template_with_editing_context():
|
|
|
|
context = {'request': True, 'post_form': object(), 'csrf_token': 'TOKEN'}
|
|
|
|
result = render({}, 'rest_framework/base.html', context=context)
|
|
|
|
# response includes a CSRF token in support of the POST form
|
|
|
|
assert re.search(r'\bcsrfToken: "TOKEN"', result.content.decode())
|