Skip to content

Commit 1cd72c3

Browse files
committed
Test {% templatetag %} and {% url %}
1 parent cbbe9ea commit 1cd72c3

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

tests/__init__.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
"""The tests for the Django Coverage Plugin."""
2+
3+
# Define URLs here so we can use ROOT_URLCONF="tests"
4+
5+
from django.conf.urls import url
6+
7+
8+
def index(request):
9+
"""A bogus view to use in the urls below."""
10+
pass
11+
12+
urlpatterns = [
13+
url(r'^home$', index, name='index'),
14+
]

tests/plugin_test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
},
2828
TEMPLATE_DEBUG=True,
2929
ALLOWED_INCLUDE_ROOTS=["/"], # for {% ssi %}
30+
ROOT_URLCONF="tests",
3031
)
3132

3233
if hasattr(django, "setup"):

tests/test_simple.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,26 @@ def test_now_as(self):
176176
self.assertEqual(text, "\nNow it's now.\n")
177177
self.assert_analysis([1, 2])
178178

179+
def test_templatetag(self):
180+
self.make_template("""\
181+
{% templatetag openblock %}
182+
url 'entry_list'
183+
{% templatetag closeblock %}
184+
""")
185+
text = self.run_django_coverage()
186+
self.assertEqual(text, "{%\nurl 'entry_list'\n%}\n")
187+
self.assert_analysis([1, 2, 3])
188+
189+
@needs_django(1, 5) # not sure why, but 1.4 won't reverse "index".
190+
def test_url(self):
191+
self.make_template("""\
192+
{% url 'index' %}
193+
nice.
194+
""")
195+
text = self.run_django_coverage()
196+
self.assertEqual(text, "/home\nnice.\n")
197+
self.assert_analysis([1, 2])
198+
179199

180200
class StringTemplateTest(DjangoPluginTestCase):
181201

0 commit comments

Comments
 (0)