Ejemplo 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)
Ejemplo 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))
Ejemplo n.º 3
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)) 
Ejemplo n.º 4
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))
Ejemplo n.º 5
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))
Ejemplo n.º 6
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))
Ejemplo n.º 7
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))
Ejemplo n.º 8
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))
Ejemplo 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))
Ejemplo n.º 10
0
    def testHtml(self):
        html = """<html>
  <head>
    <title>Alex</title>
  </head>
  <body>
    <span>Alex</span>
  </body>
</html>"""
        self.assertEquals(html, pyrazor.render(html))
Ejemplo n.º 11
0
  def testHtml(self):
    html = """<html>
  <head>
    <title>Alex</title>
  </head>
  <body>
    <span>Alex</span>
  </body>
</html>"""
    self.assertEquals(html, pyrazor.render(html))
Ejemplo n.º 12
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)
Ejemplo n.º 13
0
 def testIgnoreMultiline(self):
   """Tests that the @: does not affect output."""
   self.assertEquals("", pyrazor.render("@:\n\ta=3"))
Ejemplo n.º 14
0
 def testModelInstaceOf(self):
     m = dict()
     m['test'] = 3
     self.assertEquals("3", pyrazor.render("@model dict\n@model['test']",
                                           m))
Ejemplo n.º 15
0
 def testModelSubclassOf(self):
   class subdict(dict):
     pass
   m = subdict()
   m['test'] = 3
   self.assertEquals("3", pyrazor.render("@model dict\n@model['test']", m))
Ejemplo n.º 16
0
 def testIgnoreMultiline(self):
     """Tests that the @: does not affect output."""
     self.assertEquals("", pyrazor.render("@:\n\ta=3"))
Ejemplo n.º 17
0
 def testSimple(self):
     """Tests a simple rendering case."""
     template = "test"
     self.assertEquals(template, pyrazor.render(template))
Ejemplo n.º 18
0
 def testModelInstaceOf(self):
   m = dict()
   m['test'] = 3
   self.assertEquals("3", pyrazor.render("@model dict\n@model['test']", m))
Ejemplo n.º 19
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>"))
Ejemplo n.º 20
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"))
Ejemplo n.º 21
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>"))
Ejemplo n.º 22
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))
Ejemplo n.º 23
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"
         ))
Ejemplo n.º 24
0
 def testSimple(self):
   """Tests a simple rendering case."""
   template = "test"
   self.assertEquals(template, pyrazor.render(template))