ADD: dav_base: added test for template tag include_if_exist.

This commit is contained in:
2019-03-28 12:24:00 +01:00
parent f5abf1f815
commit e934d42d0f
9 changed files with 82 additions and 0 deletions

View 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)