|
3 | 3 | from django.shortcuts import render
|
4 | 4 |
|
5 | 5 |
|
6 |
| -def test_base_template_with_context(): |
7 |
| - context = {'request': True, 'csrf_token': 'TOKEN'} |
8 |
| - result = render({}, 'rest_framework/base.html', context=context) |
9 |
| - assert re.search(r'\bcsrfToken: "TOKEN"', result.content.decode()) |
10 |
| - |
11 |
| - |
12 | 6 | def test_base_template_with_no_context():
|
13 | 7 | # base.html should be renderable with no context,
|
14 | 8 | # so it can be easily extended.
|
15 | 9 | result = render({}, 'rest_framework/base.html')
|
16 | 10 | # note that this response will not include a valid CSRF token
|
17 | 11 | assert re.search(r'\bcsrfToken: ""', result.content.decode())
|
| 12 | + |
| 13 | + |
| 14 | +def test_base_template_with_simple_context(): |
| 15 | + context = {'request': True, 'csrf_token': 'TOKEN'} |
| 16 | + result = render({}, 'rest_framework/base.html', context=context) |
| 17 | + # note that response will STILL not include a CSRF token |
| 18 | + assert re.search(r'\bcsrfToken: ""', result.content.decode()) |
| 19 | + |
| 20 | + |
| 21 | +def test_base_template_with_editing_context(): |
| 22 | + context = {'request': True, 'post_form': object(), 'csrf_token': 'TOKEN'} |
| 23 | + result = render({}, 'rest_framework/base.html', context=context) |
| 24 | + # response includes a CSRF token in support of the POST form |
| 25 | + assert re.search(r'\bcsrfToken: "TOKEN"', result.content.decode()) |
0 commit comments