Skip to content

Commit e77fe4f

Browse files
committed
fixup! Test default_if_none template filter with dict keys
1 parent 65563d4 commit e77fe4f

File tree

1 file changed

+11
-34
lines changed

1 file changed

+11
-34
lines changed

tests/test_environment.py

Lines changed: 11 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -122,35 +122,7 @@ def test_ignore(client):
122122
ROOT_URLCONF = 'tpkg.app.urls'
123123
"""
124124
)
125-
def test_invalid_template_variable2(django_testdir):
126-
django_testdir.create_app_file(
127-
"""
128-
from django.conf.urls import url
129-
from pytest_django_test.compat import patterns
130-
131-
from tpkg.app import views
132-
133-
urlpatterns = patterns(
134-
'',
135-
url(r'the_view/', views.the_view),
136-
)
137-
""",
138-
"urls.py",
139-
)
140-
django_testdir.create_app_file(
141-
"""
142-
from django.shortcuts import render
143-
144-
145-
def the_view(request):
146-
return render(
147-
request=request,
148-
template_name='the_template.html',
149-
context={'data': {'empty': '', 'none': None}},
150-
)
151-
""",
152-
"views.py",
153-
)
125+
def test_invalid_template_with_default_if_none(django_testdir):
154126
django_testdir.create_app_file(
155127
"""
156128
<div>{{ data.empty|default:'d' }}</div>
@@ -163,14 +135,19 @@ def the_view(request):
163135
)
164136
django_testdir.create_test_module(
165137
"""
166-
import pytest
138+
def test_for_invalid_template():
139+
from django.shortcuts import render
167140
168-
def test_for_invalid_template(client):
169-
client.get('/the_view/')
141+
142+
render(
143+
request=None,
144+
template_name='the_template.html',
145+
context={'data': {'empty': '', 'none': None}},
146+
)
170147
"""
171148
)
172-
result = django_testdir.runpytest_subprocess("-s", "--fail-on-template-vars")
173-
result.stdout.fnmatch_lines_random(
149+
result = django_testdir.runpytest_subprocess("--fail-on-template-vars")
150+
result.stdout.fnmatch_lines(
174151
[
175152
"tpkg/test_the_test.py F",
176153
"E * Failed: Undefined template variable 'data.missing' in *the_template.html'",

0 commit comments

Comments
 (0)