class TemplateRunnerTestCase(unittest.TestCase):
    """Tests for template_runner.py. Run from command line with `python -m unittest test_template_runner`.
    """

    def setUp(self):
        self.runner = TemplateRunner()
        self.template_path = os.path.dirname(os.path.realpath(__file__)) + '/templates/test_template.dj.html'
        self.template = open(self.template_path, 'w')
        self.template.write('{{ test_var }}')
        self.template.close()
        self.context_path = os.path.dirname(os.path.realpath(__file__)) + '/test_contexts.py'
        self.context = open(self.context_path, 'w')
        self.context.write("CONTEXTS = {'" + self.template_path.split('/')[-1] + "': {'test_var': 'OK'}}")
        self.context.close()

    def tearDown(self):
        self.runner = None
        os.remove(self.context_path)
        os.remove(self.context_path + 'c')
        os.remove(self.template_path)
        # delete html file created
        os.remove(''.join(self.template_path.split('.dj')))

    def test_template_substitution(self):
        """Does substituting variables in templates work?"""
        self.runner.run(contexts_module='test_contexts')
        output_f_path = ''.join(self.template_path.split('.dj'))
        try:
            output_f = open(output_f_path, 'r')
        except IOError:
            raise Exception('html file not created from template')
        self.assertEqual(output_f.readline(), 'OK')
        output_f.close()
 def setUp(self):
     self.runner = TemplateRunner()
     self.template_path = os.path.dirname(os.path.realpath(__file__)) + '/templates/test_template.dj.html'
     self.template = open(self.template_path, 'w')
     self.template.write('{{ test_var }}')
     self.template.close()
     self.context_path = os.path.dirname(os.path.realpath(__file__)) + '/test_contexts.py'
     self.context = open(self.context_path, 'w')
     self.context.write("CONTEXTS = {'" + self.template_path.split('/')[-1] + "': {'test_var': 'OK'}}")
     self.context.close()