1 | """Test script to reproduce a bug with RequestContext."""
|
---|
2 |
|
---|
3 | from django.test import RequestFactory
|
---|
4 | from django.template.backends.django import DjangoTemplates
|
---|
5 | from django.template import Template, RequestContext
|
---|
6 |
|
---|
7 |
|
---|
8 | # a simple template
|
---|
9 | TEMPLATE_STRING = '{{ name }}'
|
---|
10 |
|
---|
11 | # a simple context_processer
|
---|
12 | def processor_add_name(request):
|
---|
13 | return {'name': 'foo'}
|
---|
14 |
|
---|
15 | # Django template engine
|
---|
16 | ENGINE = DjangoTemplates({
|
---|
17 | 'DIRS': [], 'APP_DIRS': False,
|
---|
18 | 'NAME': 'django',
|
---|
19 | 'OPTIONS': {
|
---|
20 | 'context_processors': [processor_add_name],
|
---|
21 | },
|
---|
22 | })
|
---|
23 |
|
---|
24 |
|
---|
25 | # testing functions, see run_tests() below
|
---|
26 | def test_base_template():
|
---|
27 | request = RequestFactory().get('/')
|
---|
28 | template = Template(TEMPLATE_STRING)
|
---|
29 | context = RequestContext(request, {}, [processor_add_name])
|
---|
30 | return template.render(context)
|
---|
31 |
|
---|
32 | def test_django_template():
|
---|
33 | request = RequestFactory().get('/')
|
---|
34 | template = ENGINE.from_string(TEMPLATE_STRING)
|
---|
35 | context = RequestContext(request, {})
|
---|
36 | return template.render(context)
|
---|
37 |
|
---|
38 | def test_django_template_explicit_processors():
|
---|
39 | request = RequestFactory().get('/')
|
---|
40 | template = ENGINE.from_string(TEMPLATE_STRING)
|
---|
41 | context = RequestContext(request, {}, [processor_add_name])
|
---|
42 | return template.render(context)
|
---|
43 |
|
---|
44 |
|
---|
45 | def run_tests():
|
---|
46 | assert test_base_template() == 'foo'
|
---|
47 | # The next two fail, both functions return '' (empty string).
|
---|
48 | assert test_django_template() == 'foo'
|
---|
49 | assert test_django_template_explicit_processors() == 'foo'
|
---|