예제 #1
0
    def test_render_template(self):
        app = Tipfy(config={'tipfyext.mako': {'templates_dir': templates_dir}})
        request = Request.from_values()
        local.current_handler = handler = RequestHandler(app, request)
        mako = Mako(app)

        message = 'Hello, World!'
        res = mako.render_template(local.current_handler, 'template1.html', message=message)
        self.assertEqual(res, message + '\n')
예제 #2
0
    def test_render_response(self):
        app = Tipfy(config={'tipfyext.mako': {'templates_dir': templates_dir}})
        request = Request.from_values()
        local.current_handler = handler = RequestHandler(app, request)
        mako = Mako(app)

        message = 'Hello, World!'
        response = mako.render_response(local.current_handler, 'template1.html', message=message)
        self.assertEqual(isinstance(response, Response), True)
        self.assertEqual(response.mimetype, 'text/html')
        self.assertEqual(response.data, message + '\n')
예제 #3
0
    def test_mako_mixin_render_template(self):
        class MyHandler(RequestHandler, MakoMixin):
            def __init__(self, app, request):
                self.app = app
                self.request = request
                self.context = {}

        app = Tipfy(config={'tipfyext.mako': {'templates_dir': templates_dir}})
        request = Request.from_values()
        local.current_handler = handler = MyHandler(app, request)
        mako = Mako(app)
        message = 'Hello, World!'

        response = handler.render_template('template1.html', message=message)
        self.assertEqual(response, message + '\n')
예제 #4
0
    def test_mako_mixin_render_response(self):
        class MyHandler(RequestHandler, MakoMixin):
            def __init__(self, app, request):
                self.app = app
                self.request = request
                self.context = {}

        app = Tipfy(config={'tipfyext.mako': {'templates_dir': templates_dir}})
        request = Request.from_values()
        handler = MyHandler(app, request)
        mako = Mako(app)
        message = 'Hello, World!'

        response = handler.render_response('template1.html', message=message)
        self.assertEqual(isinstance(response, Response), True)
        self.assertEqual(response.mimetype, 'text/html')
        self.assertEqual(response.data, message + '\n')