Ejemplo n.º 1
0
    def test_engine_func(self):
        def engine(data, template=None):
            return 'text/plain', data

        render = Engines()
        render['raw'] = engine

        self.assertEqual(render.raw("foo"), ('text/plain', 'foo'))

        del render.raw
Ejemplo n.º 2
0
    def test_engine_class(self):
        class Engine(object):
            def __call__(self, data, template=None):
                return 'text/plain', data

        render = Engines()
        render['raw'] = Engine

        self.assertEqual(render.raw("foo"), ('text/plain', 'foo'))

        del render.raw
Ejemplo n.º 3
0
class TestTemplating(TestCase):
    def setUp(self):
        self.render = Engines()

    def test_formatter_string(self):
        self.assertEqual(self.render.formatter(dict(name="world"), string="Hello {name}!"),
                ('text/plain', 'Hello world!'))

    def test_formatter_file(self):
        self.assertEqual(self.render.formatter(dict(name="world"), './tests/templates/hello-formatter.txt'),
                ('text/plain', 'Hello world!'))

    def test_sprintf_string(self):
        self.assertEqual(self.render.sprintf(dict(name="world"), string="Hello %(name)s!"),
                ('text/plain', 'Hello world!'))

    def test_sprintf_file(self):
        self.assertEqual(self.render.sprintf(dict(name="world"), './tests/templates/hello-sprintf.txt'),
                ('text/plain', 'Hello world!'))

    def test_template_string(self):
        self.assertEqual(self.render.template(dict(name="world"), string="Hello $name!"),
                ('text/plain', 'Hello world!'))

    def test_template_string_unsafe(self):
        self.assertEqual(self.render.template(dict(name="world"), string="Hello $name!", safe=False),
                ('text/plain', 'Hello world!'))

    def test_template_file(self):
        self.assertEqual(self.render.template(dict(name="world"), './tests/templates/hello-template.txt'),
                ('text/plain', 'Hello world!'))
Ejemplo n.º 4
0
    def test_defaults(self):
        render = Engines(json=dict(content_type="foo"))
        self.assertEqual(render.options['json'], dict(content_type="foo"))

        render.options['json'] = dict(content_type="bar")
        self.assertEqual(render.options['json'], dict(content_type="bar"))
Ejemplo n.º 5
0
 def setUp(self):
     self.render = Engines()