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,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' %}--

View File

@@ -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' %}--

View File

@@ -0,0 +1,3 @@
{% load dav_base %}
This template is used by the automatic software tests.
--{% include_if_exist './includes/include_optional.html' default %}--

View File

@@ -0,0 +1,3 @@
{% load dav_base %}
This template is used by the automatic software tests.
--{% include_if_exist './includes/include_optional.html' 'bogus' %}--

View File

@@ -0,0 +1,3 @@
{% load dav_base %}
This template is used by the automatic software tests.
--{% include_if_exist %}--

View File

@@ -0,0 +1 @@
{# This template is used by software tests #}DEFAULT INCLUDED HTML

View File

@@ -0,0 +1 @@
{# This template is used by software tests #}OPTIONAL INCLUDED HTML

View File

@@ -0,0 +1,2 @@
{# This template is used by software tests #}{% load dav_base %}
--{% include './include_missing.html' %}--

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)