Example #1
0
 def test_render_from_string(self):
     """Test that the templating module render_from_string works ok"""
     
     
     template = ">>$one<< >>$two<< >>${three}<<"
     
     # render with all variables of different types
     d = {'one': 1, 'two': 'two', 'three': [3]}
     
     self.assertEqual([b">>1<< >>two<< >>[3]<<"], templating.render_from_string(template, d))
     
     # with missing values
     d = {'one': 1}
     
     self.assertEqual([b">>1<< >>$two<< >>${three}<<"], templating.render_from_string(template, d))
Example #2
0
 def test_render(self):
     """Test that the templating render works rendering from a file"""
     
     template = ">>$one<< >>$two<< >>${three}<<"
     
     (handle, filepath) = tempfile.mkstemp(dir=templating.TEMPLATE_DIR)
     self.addCleanup(lambda: os.unlink(filepath))
     
     os.write(handle, template.encode())
     os.close(handle)
     
     templatename = os.path.basename(filepath)
     
     # render with all variables
     d = {'one': 1, 'two': 'two', 'three': [3]}
     
     self.assertEqual([b">>1<< >>two<< >>[3]<<"], templating.render(templatename, d))
     # with missing values
     d = {'one': 1}
     
     self.assertEqual([b">>1<< >>$two<< >>${three}<<"], templating.render_from_string(template, d))