ADD: dav_base: added test for template tag include_if_exist.
This commit is contained in:
6
dav_base/templates/dav_base/tests/include_if_exist.html
Normal file
6
dav_base/templates/dav_base/tests/include_if_exist.html
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
{# This template is used by software tests #}{% load dav_base %}
|
||||||
|
--{% include_if_exist './includes/include_missing.html' %}--
|
||||||
|
--{% include_if_exist './includes/include_missing.html' default 'dav_base/tests/includes/include_default.html' %}--
|
||||||
|
--{% include_if_exist './includes/include_optional.html' %}--
|
||||||
|
--{% include_if_exist './includes/include_optional.html' default 'dav_base/tests/includes/include_default.html' %}--
|
||||||
|
--{% include_if_exist './includes/include_with_missing_include.html' %}--
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
{# This template is used by software tests #}{% load dav_base %}
|
||||||
|
--{% include_if_exist './includes/include_missing.html' default './includes/include_missing.html' %}--
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
{% load dav_base %}
|
||||||
|
This template is used by the automatic software tests.
|
||||||
|
--{% include_if_exist './includes/include_optional.html' default %}--
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
{% load dav_base %}
|
||||||
|
This template is used by the automatic software tests.
|
||||||
|
--{% include_if_exist './includes/include_optional.html' 'bogus' %}--
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
{% load dav_base %}
|
||||||
|
This template is used by the automatic software tests.
|
||||||
|
--{% include_if_exist %}--
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
{# This template is used by software tests #}DEFAULT INCLUDED HTML
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
{# This template is used by software tests #}OPTIONAL INCLUDED HTML
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
{# This template is used by software tests #}{% load dav_base %}
|
||||||
|
--{% include './include_missing.html' %}--
|
||||||
61
dav_base/tests/test_templatetags.py
Normal file
61
dav_base/tests/test_templatetags.py
Normal file
@@ -0,0 +1,61 @@
|
|||||||
|
from django.template.exceptions import TemplateSyntaxError, TemplateDoesNotExist
|
||||||
|
from django.template.loader import get_template
|
||||||
|
from django.test import SimpleTestCase
|
||||||
|
|
||||||
|
|
||||||
|
class TemplateTagsTestCase(SimpleTestCase):
|
||||||
|
def test_include_if_exist_without_argument(self):
|
||||||
|
template_name = 'dav_base/tests/include_if_exist_without_argument.html'
|
||||||
|
with self.assertRaises(TemplateSyntaxError):
|
||||||
|
get_template(template_name)
|
||||||
|
|
||||||
|
def test_include_if_exist_with_unexpected_argument(self):
|
||||||
|
template_name = 'dav_base/tests/include_if_exist_with_unexpected_argument.html'
|
||||||
|
with self.assertRaises(TemplateSyntaxError):
|
||||||
|
get_template(template_name)
|
||||||
|
|
||||||
|
def test_include_if_exist_default_without_argument(self):
|
||||||
|
template_name = 'dav_base/tests/include_if_exist_default_without_argument.html'
|
||||||
|
with self.assertRaises(TemplateSyntaxError):
|
||||||
|
get_template(template_name)
|
||||||
|
|
||||||
|
def test_include_if_exist_default_missing(self):
|
||||||
|
template_name = 'dav_base/tests/include_if_exist_default_missing.html'
|
||||||
|
with self.settings(DEBUG=True):
|
||||||
|
with self.assertRaises(TemplateDoesNotExist):
|
||||||
|
template = get_template(template_name)
|
||||||
|
template.render()
|
||||||
|
|
||||||
|
def test_include_if_exist(self):
|
||||||
|
template_name = 'dav_base/tests/include_if_exist.html'
|
||||||
|
template = get_template(template_name)
|
||||||
|
|
||||||
|
content = template.render()
|
||||||
|
expected_content = """
|
||||||
|
----
|
||||||
|
--DEFAULT INCLUDED HTML--
|
||||||
|
--OPTIONAL INCLUDED HTML--
|
||||||
|
--OPTIONAL INCLUDED HTML--
|
||||||
|
--
|
||||||
|
----
|
||||||
|
--
|
||||||
|
"""
|
||||||
|
|
||||||
|
self.assertEqual(content, expected_content)
|
||||||
|
|
||||||
|
def test_include_if_exist_while_debug(self):
|
||||||
|
template_name = 'dav_base/tests/include_if_exist.html'
|
||||||
|
|
||||||
|
with self.settings(DEBUG=True):
|
||||||
|
template = get_template(template_name)
|
||||||
|
|
||||||
|
content = template.render()
|
||||||
|
expected_content = """
|
||||||
|
----
|
||||||
|
--DEFAULT INCLUDED HTML--
|
||||||
|
--OPTIONAL INCLUDED HTML--
|
||||||
|
--OPTIONAL INCLUDED HTML--
|
||||||
|
----
|
||||||
|
"""
|
||||||
|
|
||||||
|
self.assertEqual(content, expected_content)
|
||||||
Reference in New Issue
Block a user