Пример #1
0
    def test_template_with_controller_and_not_existent_template(self):

        dummy = self.dummy
        template = Template(controller=dummy)
        self.assertEqual(
            template.render('dummy_test.html',
                            title='Dummy Test',
                            content='Dummy'), u'<!DOCTYPE html>\n'
            '<html lang="en">\n'
            '<head>\n'
            '    <title>Dummy Test Controller</title>\n'
            '</head>\n'
            '<body>\n'
            '    Dummy\n'
            '</body>\n'
            '</html>')
Пример #2
0
    def test_template_with_controller_and_not_existent_template(self):

        dummy = self.dummy
        template = Template(controller=dummy)
        self.assertEqual(
            template.render(
                'dummy_test.html',
                title='Dummy Test',
                content='Dummy'
            ),
            u'<!DOCTYPE html>\n'
            '<html lang="en">\n'
            '<head>\n'
            '    <title>Dummy Test Controller</title>\n'
            '</head>\n'
            '<body>\n'
            '    Dummy\n'
            '</body>\n'
            '</html>'
        )
Пример #3
0
    def setUp(self):
        self.currdir = os.getcwd()
        os.chdir('../mamba/test/dummy_app')

        self.dummy = DummyController()
        self.template = Template(size=0)
Пример #4
0
class TemplateTest(unittest.TestCase):

    def setUp(self):
        self.currdir = os.getcwd()
        os.chdir('../mamba/test/dummy_app')

        self.dummy = DummyController()
        self.template = Template(size=0)

    def tearDown(self):
        os.chdir(self.currdir)

    def test_template_without_controller(self):

        self.assertEqual(
            self.template.render(
                'dummy.html',
                title='Dummy Test',
                content='Dummy'
            ),
            u'<!DOCTYPE html>\n'
            '<html lang="en">\n'
            '<head>\n'
            '    <title>Dummy Test</title>\n'
            '</head>\n'
            '<body>\n'
            '    Dummy\n'
            '</body>\n'
            '</html>'
        )

    def test_template_with_controller_and_not_existent_template(self):

        dummy = self.dummy
        template = Template(controller=dummy)
        self.assertEqual(
            template.render(
                'dummy_test.html',
                title='Dummy Test',
                content='Dummy'
            ),
            u'<!DOCTYPE html>\n'
            '<html lang="en">\n'
            '<head>\n'
            '    <title>Dummy Test Controller</title>\n'
            '</head>\n'
            '<body>\n'
            '    Dummy\n'
            '</body>\n'
            '</html>'
        )

    def test_template_with_controller_and_not_template_argument(self):

        def dummy_test(self):
            return Template(controller=self).render(
                title='Dummy Test', content='Dummy')

        dummy = self.dummy
        dummy.dummy_test = dummy_test
        self.assertEqual(
            dummy.dummy_test(dummy),
            u'<!DOCTYPE html>\n'
            '<html lang="en">\n'
            '<head>\n'
            '    <title>Dummy Test Controller</title>\n'
            '</head>\n'
            '<body>\n'
            '    Dummy\n'
            '</body>\n'
            '</html>'
        )

    def test_template_with_template_arg_on_render_hides_controller(self):

        def dummy_test2(self):
            return Template(controller=self, size=0).render(
                template='dummy_test2.html')

        dummy = self.dummy
        dummy.dummy_test2 = dummy_test2
        self.assertEqual(dummy.dummy_test2(dummy), 'HIDDEN!')

    def test_template_raises_templatenotfound_on_non_existent(self):
        self.assertRaises(
            TemplateNotFound,
            self.template.render, 'fail.html'
        )

    def test_template_raises_notconfigured_when_no_arguments(self):
        self.assertRaises(
            NotConfigured,
            self.template.render
        )
Пример #5
0
 def dummy_test(self):
     return Template(controller=self).render(title='Dummy Test',
                                             content='Dummy')
Пример #6
0
    def setUp(self):
        self.currdir = os.getcwd()
        os.chdir('../mamba/test/dummy_app')

        self.dummy = DummyController()
        self.template = Template(size=0)
Пример #7
0
class TemplateTest(unittest.TestCase):
    def setUp(self):
        self.currdir = os.getcwd()
        os.chdir('../mamba/test/dummy_app')

        self.dummy = DummyController()
        self.template = Template(size=0)

    def tearDown(self):
        os.chdir(self.currdir)

    def test_template_without_controller(self):

        self.assertEqual(
            self.template.render('dummy.html',
                                 title='Dummy Test',
                                 content='Dummy'), u'<!DOCTYPE html>\n'
            '<html lang="en">\n'
            '<head>\n'
            '    <title>Dummy Test</title>\n'
            '</head>\n'
            '<body>\n'
            '    Dummy\n'
            '</body>\n'
            '</html>')

    def test_template_with_controller_and_not_existent_template(self):

        dummy = self.dummy
        template = Template(controller=dummy)
        self.assertEqual(
            template.render('dummy_test.html',
                            title='Dummy Test',
                            content='Dummy'), u'<!DOCTYPE html>\n'
            '<html lang="en">\n'
            '<head>\n'
            '    <title>Dummy Test Controller</title>\n'
            '</head>\n'
            '<body>\n'
            '    Dummy\n'
            '</body>\n'
            '</html>')

    def test_template_with_controller_and_not_template_argument(self):
        def dummy_test(self):
            return Template(controller=self).render(title='Dummy Test',
                                                    content='Dummy')

        dummy = self.dummy
        dummy.dummy_test = dummy_test
        self.assertEqual(
            dummy.dummy_test(dummy), u'<!DOCTYPE html>\n'
            '<html lang="en">\n'
            '<head>\n'
            '    <title>Dummy Test Controller</title>\n'
            '</head>\n'
            '<body>\n'
            '    Dummy\n'
            '</body>\n'
            '</html>')

    def test_template_with_template_arg_on_render_hides_controller(self):
        def dummy_test2(self):
            return Template(controller=self,
                            size=0).render(template='dummy_test2.html')

        dummy = self.dummy
        dummy.dummy_test2 = dummy_test2
        self.assertEqual(dummy.dummy_test2(dummy), 'HIDDEN!')

    def test_template_raises_templatenotfound_on_non_existent(self):
        self.assertRaises(TemplateNotFound, self.template.render, 'fail.html')

    def test_template_raises_notconfigured_when_no_arguments(self):
        self.assertRaises(NotConfigured, self.template.render)
Пример #8
0
 def dummy_test2(self):
     return Template(controller=self,
                     size=0).render(template='dummy_test2.html')