def test_media_render(self): '''Make sure media isn't duplicated.''' c = Context() t = Template( "{% load widget_tags %}" "<head>{% include \"widgets/head.html\" %}</head>" "{% widget widgets.tests.TestWidget3 %}" "{% widget widgets.tests.TestWidget3 %}") wt = WidgetTemplateWrapper(t) head = etree.fromstring(wt.render(c)) self.assertEqual(head.tag, "head") self.assertEqual(len(head.getchildren()), 6) # Match rendered CSS css = head.findall("link") self.assertEqual(len(css), 3) hrefs = list(e.get('href') for e in css) test_widget_3 = TestWidget3() self.assertEqual( map(lambda x: "%s%s" % (settings.MEDIA_URL, x), test_widget_3.css_media), hrefs) # Match rendered JS js = head.findall("script") self.assertEqual(len(js), 3) srcs = list(e.get('src') for e in js) self.assertEqual( map(lambda x: "%s%s" % (settings.MEDIA_URL, x), test_widget_3.js_media), srcs)
def test_empty_widget(self): c = Context() t = Template( "{% load widget_tags %}" "{% include \"widgets/head.html\" %}" "{% widget widgets.base.WidgetBase %}") wt = WidgetTemplateWrapper(t) text = wt.render(c).strip() self.assertEqual(text, "")
def test_extensions(self): """Check 3 levels of extension.""" t = get_template("widgets/test/extenderC.html") c = Context() wt = WidgetTemplateWrapper(t) wt.render(c) as_names = [w.as_name.literal for w in wt.widget_nodes] as_names = set(as_names) self.assertEqual(as_names, set([ 'ablockC', 'cblockC', 'ablockB', 'bblockB', 'ablockA', 'cblockA', # this one actually gets overriden, see note \/ ]))
def test_extend_inner_block(self): """Check 4 levels of extension, with an inner block overriden.""" t = get_template("widgets/test/extenderD.html") c = Context() wt = WidgetTemplateWrapper(t) wt.render(c) as_names = [w.as_name.literal or w.as_name.var for w in wt.widget_nodes] as_names = set(as_names) self.assertEqual(as_names, set([ 'ablockC', 'cblockC', 'ablockB', 'bblockB', 'ablockA', 'cblockA', 'dblockD', ]))