11# -*- coding: utf-8 -*-
2- from django .template import Context , Template
2+ from django .template import Context , Template , TemplateSyntaxError
33from django .test import SimpleTestCase
44from django .utils .safestring import mark_safe
55
@@ -9,6 +9,7 @@ class HtmlTagNodeTest(SimpleTestCase):
99 SAMPLE_CONTENT_UNICODE = 'Lörém ípsüm'
1010 SAMPLE_CSS = 'simple sample'
1111 SAMPLE_TAG = 'span'
12+ SAMPLE_INVALID_TAG = 'foo'
1213
1314 HTMLTAG_START = mark_safe ('<div>' )
1415 HTMLTAG_CSS_CLASSES_START = mark_safe ('<div class="' + SAMPLE_CSS + '">' )
@@ -44,7 +45,7 @@ def setUp(self):
4445
4546 def test_htmltag_is_rendered (self ):
4647 rendered = self .TEMPLATE_SIMPLE .render (Context ({}))
47- self .assertIn (self .HTMLTAG_START + self .HTMLTAG_END , rendered )
48+ self .assertInHTML (self .HTMLTAG_START + self .HTMLTAG_END , rendered )
4849
4950 def test_htmltag_content_is_rendered (self ):
5051 rendered = self .TEMPLATE_CONTENT .render (Context ({'content' : self .SAMPLE_CONTENT }))
@@ -56,11 +57,33 @@ def test_htmltag_content_unicode_is_rendered(self):
5657
5758 def test_htmltag_css_classes_are_rendered (self ):
5859 rendered = self .TEMPLATE_CSS .render (Context ({'css' : self .SAMPLE_CSS }))
59- self .assertIn (self .HTMLTAG_CSS_CLASSES_START + self .HTMLTAG_END , rendered )
60+ self .assertInHTML (self .HTMLTAG_CSS_CLASSES_START + self .HTMLTAG_END , rendered )
6061
6162 def test_htmltag_tag_is_rendered (self ):
6263 rendered = self .TEMPLATE_TAG .render (Context ({'tag' : self .SAMPLE_TAG }))
63- self .assertIn (self .HTMLTAG_TAG_START + self .HTMLTAG_TAG_END , rendered )
64+ self .assertInHTML (self .HTMLTAG_TAG_START + self .HTMLTAG_TAG_END , rendered )
65+
66+ def test_htmltag_invalid_tag_raises_exception (self ):
67+ with self .assertRaises (TemplateSyntaxError ):
68+ self .TEMPLATE_TAG .render (Context ({'tag' : self .SAMPLE_INVALID_TAG }))
69+
70+
71+ class BootstrapTagsTest (SimpleTestCase ):
72+ HTMLTAG_START = mark_safe ('<div class="bs">' )
73+ HTMLTAG_END = mark_safe ('</div>' )
74+
75+ TEMPLATE_SIMPLE = Template (
76+ '{% load bootstrap_ui_tags %}'
77+ '{% bootstraptag %}'
78+ '{% endbootstraptag %}'
79+ )
80+
81+ def setUp (self ):
82+ pass
83+
84+ def test_bootstraptag_is_rendered (self ):
85+ rendered = self .TEMPLATE_SIMPLE .render (Context ({}))
86+ self .assertInHTML (self .HTMLTAG_START + self .HTMLTAG_END , rendered )
6487
6588
6689class ListGroupTagsTest (SimpleTestCase ):
@@ -109,13 +132,16 @@ def test_list_group_item_in_list_group_is_rendered(self):
109132
110133 def test_list_group_item_default_tag_is_rendered (self ):
111134 rendered = self .TEMPLATE_SIMPLE .render (Context ({}))
112- self .assertIn (self .LIST_GROUP_ITEM_START , rendered )
113- self .assertIn (self .LIST_GROUP_ITEM_END , rendered )
135+ self .assertInHTML (self .LIST_GROUP_ITEM_START + self .LIST_GROUP_ITEM_END , rendered )
114136
115137 def test_list_group_item_link_is_rendered (self ):
116138 rendered = self .TEMPLATE_LINK .render (Context ({'sample_link' : self .SAMPLE_LINK , 'sample_label' : self .SAMPLE_LABEL }))
117139 self .assertInHTML (self .LIST_GROUP_ITEM_LINK_START + self .SAMPLE_LABEL + self .LIST_GROUP_ITEM_LINK_END , rendered )
118140
141+ def test_list_group_item_link_without_destination_raises_exception (self ):
142+ with self .assertRaises (TemplateSyntaxError ):
143+ self .TEMPLATE_LINK .render (Context ({}))
144+
119145
120146class PanelTagsTest (SimpleTestCase ):
121147 SAMPLE_HEADING = 'Lorem ipsum heading'
@@ -169,7 +195,7 @@ def setUp(self):
169195
170196 def test_panel_is_rendered (self ):
171197 rendered = self .TEMPLATE_SIMPLE .render (Context ({}))
172- self .assertIn (
198+ self .assertInHTML (
173199 self .PANEL_START
174200 + self .PANEL_HEADING_START + self .PANEL_HEADING_END
175201 + self .PANEL_BODY_START + self .PANEL_BODY_END
0 commit comments