Esempio n. 1
0
  def testTmpl(self):
    """Tests that the tmpl directive renders correctly"""
    class model:
      pass

    tmpl_file = RenderTests.__writeTemplateToFile("Test")
    try:
      template = '@view.tmpl("' + tmpl_file + '")'
      self.assertEquals("Test", pyrazor.Render(template))
    finally:
      os.remove(tmpl_file)

    tmpl_file = RenderTests.__writeTemplateToFile("<head>\n\[email protected]\n</head>")
    try:
      template = '@view.tmpl("' + tmpl_file + '")'
      m = model()
      m.title = "test"
      self.assertEquals("<head>\n\ttest\n</head>", pyrazor.Render(template, m))
    finally:
      os.remove(tmpl_file)

    # Tests that we pass the appropriate part of a model
    tmpl_file = RenderTests.__writeTemplateToFile("<head>\n\[email protected]\n</head>")
    try:
      template = '@model.title\[email protected]("' + tmpl_file + '", model.sub)'
      m = model()
      m.title = "Top title"
      m.sub = model()
      m.sub.title = "Sub Title"
      self.assertEquals("Top title\n<head>\n\tSub Title\n</head>", pyrazor.Render(template, m))
    finally:
      os.remove(tmpl_file)
Esempio n. 2
0
 def testMultilineIf(self):
   """Tests that an if statement works"""
   # The renderer will output True\n and False\n due to new line chars.... theres currently no good way around this.
   # Though it's not really a huge issue except when testing for an exact match.
   template = "@if model:\n\tTrue\n@else:\n\tFalse"
   self.assertEquals("True\n", pyrazor.Render(template, True)) 
   self.assertEquals("False", pyrazor.Render(template, False)) 
Esempio n. 3
0
  def testHtmlEscape(self):
    class test:
      pass

    model = test()
    model.a = "<html>"
    self.assertEquals("<html>", pyrazor.Render("@!model.a", model))
    self.assertEquals(cgi.escape("<html>"), pyrazor.Render("@model.a", model))
    self.assertEquals("<html>", pyrazor.Render("@!(model.a)", model))
    self.assertEquals(cgi.escape("<html>"), pyrazor.Render("@(model.a)", model))
Esempio n. 4
0
  def testSimpleModel(self): 
    class test:
      pass

    model = test()
    model.a = 3
    model.b = 5
    self.assertEquals("3", pyrazor.Render("@model.a", model))
    self.assertEquals("3 5", pyrazor.Render("@model.a @model.b", model))
    self.assertEquals("8", pyrazor.Render("@(model.a + model.b)", model))
Esempio n. 5
0
 def testHtml(self):
   html = textwrap.dedent("""\
       <html>
         <head>
           <title>Alex</title>
         </head>
         <body>
           <span>Alex</span>
         </body>
       </html>""")
   self.assertEquals(html, pyrazor.Render(html))
Esempio n. 6
0
 def testHelperFunction(self):
   self.assertEquals("viewtext\n<s>helper</s>\nviewtext", pyrazor.Render("@helper test(name):\n\t<s>@name</s>\nviewtext\n@test('helper')\nviewtext"))
Esempio n. 7
0
 def testCommentIgnored(self):
   self.assertEquals("<html></html>", pyrazor.Render("<html>@# Comment! #@</html>"))
   self.assertEquals("<html>\n</html>", pyrazor.Render("<html>\n@#A whole line is commented!\n</html>"))
Esempio n. 8
0
 def testIgnoreWhitespace(self):
   """Tests that ignoring whitespace will strip all tab/spaces prefix on a line"""
   self.assertEquals("test\ntest", pyrazor.Render("test\n\ttest", ignore_whitespace=True))
   self.assertEquals("test", pyrazor.Render("  test", ignore_whitespace=True))
   self.assertEquals("test", pyrazor.Render("\t test", ignore_whitespace=True))
   self.assertEquals("test\ntest", pyrazor.Render("\t test\n\t\ttest", ignore_whitespace=True))
Esempio n. 9
0
 def testModelSubclassOf(self):
   class subdict(dict):
     pass
   m = subdict()
   m['test'] = 3
   self.assertEquals("3", pyrazor.Render("@model dict\n@model['test']", m))
Esempio n. 10
0
 def testModelInstaceOf(self):
   m = dict()
   m['test'] = 3
   self.assertEquals("3", pyrazor.Render("@model dict\n@model['test']", m))
Esempio n. 11
0
 def testIgnoreMultiline(self):
   """Tests that the @: does not affect output."""
   self.assertEquals("", pyrazor.Render("@:\n\ta=3"))
Esempio n. 12
0
 def testSimple(self):
   """Tests a simple rendering case."""
   template = "test"
   self.assertEquals(template, pyrazor.Render(template))