def setUp(self): self.beard = BeardTemplateEngine()
class BeardEngineTest(TestCase): def setUp(self): self.beard = BeardTemplateEngine() def test_render(self): """ Render empty string """ tpl = "" result = self.beard.render(tpl) self.assertEqual(result, "") def test_render2(self): """ Render simple text """ tpl = "yop" result = self.beard.render(tpl) self.assertEqual(result, "yop") def test_render3(self): """ Render simple default variable value """ tpl = "<%= my_unset_variable | yop %>" result = self.beard.render(tpl) exp_result = "yop" self.assertEqual(result, exp_result) def test_render4(self): """ Render simple variable value """ tpl = "<%= my_set_variable | yop %>" self.beard.variables["my_set_variable"] = "hello" result = self.beard.render(tpl) exp_result = "hello" self.assertEqual(result, exp_result) def test_complex(self): """ Complex test with real data """ # set element self.beard.elements["test_element"] = "I'm a sub element" # set variables self.beard.variables["cdn"] = "http://somecdndomain.com" self.beard.variables["browser_view_url"] = "http://someurl.com" # initialize plugin self.beard.plugins["linkgatagger"] = LinkGATagger(source="source_test", medium="email") with open("./tests/html/data.html", "r") as f: data = f.read() # check values before test self.assertIn('href=http://www.picknews.com/contact-us class=cnc_track_contact_support', data) self.assertIn('href=http://www.picknews.com/add_site class=cnc_track_add_custom_website', data) result = self.beard.render(data) # check variables self.assertIn("http://somecdndomain.com", result) self.assertIn("http://someurl.com", result) # check plugin modifications self.assertIn('href="http://www.picknews.com/contact-us?utm_medium=email&utm_source=source_test&utm_campain=contact_support" class=', result) self.assertIn('href="http://www.picknews.com/add_site?utm_medium=email&utm_source=source_test&utm_campain=add_custom_website" class=', result)