File: test_templates.py

package info (click to toggle)
djangorestframework 3.14.0-2%2Bdeb12u1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 16,984 kB
  • sloc: python: 27,822; javascript: 25,191; makefile: 26; sh: 6
file content (17 lines) | stat: -rw-r--r-- 601 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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())