def test_template_context(self): # insertion of context variables f1 = Frame.objects.create(format='template', content='{% if true %}YES{% else %}NO{% endif %}') r1 = f1.draw(context={'true': True}) self.failIfStringContains(r1, 'NO') # the 'frame' context variable f2 = Frame.objects.create(format='template', content='{% ifequal this_frame the_frame %}YES{% else %}NO{% endifequal %}') r2 = f2.draw(context={'the_frame': f2}) self.failIfStringContains(r2, 'NO') # insertion of context when using deco.quick.draw() f3 = Frame.objects.create(title='the_frame', format='template', content='{{ the_var }}') r3 = draw('the_frame', context={'the_var': 'bla!'}) self.failUnless(r3 == 'bla!') # getting parent_context data when a frame is drawn from a templatetag f4 = Frame.objects.create(format='template', content='{{ the_var }}') r4 = Template('{% load deco_tags %}{% frame f d %}').render(Context({'d': {'the_var': 'bla'}, 'f': f4})) self.failUnless(r4 == 'bla') # recurrently drawing a frame f5 = Frame.objects.create(format='template', content= '{% load deco_tags %}{{ txt }}{% if items %}' + '[{% for item in items %}{% frame this_frame item %}{% endfor %}]' + '{% endif %}') r5 = f5.draw(context={ 'txt': 1, 'items': ({'txt': '2'}, {'items': ({'txt': 3}, {'txt': '4'})}, {'txt':'5'})}) self.failUnless(r5 == '1[2[34]5]')
def test_frame(self): # test rendering of text frames f1 = Frame.objects.create(title='Text Page', format='text', content="page <i>content</i>") r1 = f1.draw() self.failUnlessStringContains(r1, "page <i>content</i>") self.failUnless(isinstance(r1, SafeData)) # test rendering of html frames f2 = Frame(format='html', content="page <i>content</i>") r2 = f2.draw() self.failUnlessStringContains(r2, "page <i>content</i>") self.failUnless(isinstance(r2, SafeData)) # test rendering of template frames f3 = Frame(format='template', content="page {% if 1 %}<i>content</i>{% else %}NO{% endif %}") r3 = f3.draw() self.failUnlessStringContains(r3, "<i>content</i>") self.failIfStringContains(r3, "NO") self.failUnless(isinstance(r3, SafeData)) # test the standalone "draw" function r1_2 = draw("Text Page") self.failUnless(r1_2 == r1) # test rendering of non-existent frames def make_bad_frame(): Frame(title="BadFormat Page", content="page <i>content</i>", format='no_such_format').draw() self.failUnlessRaises(TypeError, make_bad_frame)
def test_nonexistent_frame(self): self.failUnlessStringContains(draw("no_such_view"), '[view with title "no_such_view" does not exist]')