mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-28 04:24:00 +03:00
513a49d63b
A Python 3 cleanup that allows for less noise in the code. https://docs.python.org/3/library/stdtypes.html#bytes.decode https://docs.python.org/3/library/stdtypes.html#str.encode
18 lines
601 B
Python
18 lines
601 B
Python
import re
|
|
|
|
from django.shortcuts import render
|
|
|
|
|
|
def test_base_template_with_context():
|
|
context = {'request': True, 'csrf_token': 'TOKEN'}
|
|
result = render({}, 'rest_framework/base.html', context=context)
|
|
assert re.search(r'\bcsrfToken: "TOKEN"', result.content.decode())
|
|
|
|
|
|
def test_base_template_with_no_context():
|
|
# base.html should be renderable with no context,
|
|
# so it can be easily extended.
|
|
result = render({}, 'rest_framework/base.html')
|
|
# note that this response will not include a valid CSRF token
|
|
assert re.search(r'\bcsrfToken: ""', result.content.decode())
|