I am using Jinja2 with Webapp2 in a GAE project.
I have a RequestHandler base, as described in webapp2_extras.jinja2 :
import webapp2 from webapp2_extras import jinja2 def jinja2_factory(app): """Set configuration environment for Jinja.""" config = {my config...} j = jinja2.Jinja2(app, config=config) return j class BaseHandler(webapp2.RequestHandler): @webapp2.cached_property def jinja2(self):
And a view handler:
class MyHandler(BaseHandler): def get(self): context = {'message': 'Hello, world!'} self.render_response('my_template.html', **context)
My templates are in the default location ( templates ).
The application works well on the dev server, and the template displays correctly.
But when I try unittest MyHandler with
import unittest import webapp2 import webstest class MyHandlerTest(unittest.TestCase): def setUp(self): application = webapp2.WSGIApplication([('/', MyHandler)]) self.testapp = webtest.TestApp(application) def test_response(self): response = application.get_response('/') ...
application.get_response('/my-view') throws an exception: TemplateNotFound: my_template.html .
Is there something I missed? How is jinja2 environment loader or template configuration?
source share