def test_with_extension(self): from pyramid_jinja2 import IJinja2Environment self.config.registry.settings.update({ 'jinja2.directories': self.templates_dir, 'jinja2.extensions': """ pyramid_jinja2.tests.extensions.TestExtension """ }) info = DummyRendererInfo({ 'name': 'helloworld.jinja2', 'package': None, 'registry': self.config.registry, }) renderer = self._callFUT(info) environ = self.config.registry.getUtility(IJinja2Environment) self.assertEqual(environ.loader.searchpath, [self.templates_dir]) self.assertEqual(renderer.info, info) self.assertEqual(renderer.environment, environ) import pyramid_jinja2.tests.extensions ext = environ.extensions[ 'pyramid_jinja2.tests.extensions.TestExtension'] self.assertEqual(ext.__class__, pyramid_jinja2.tests.extensions.TestExtension)
def test_call_with_nondict_value(self): environ = DummyEnvironment() info = DummyRendererInfo({ 'name': 'name', }) instance = self._makeOne(info, environ) self.assertRaises(ValueError, instance, None, {'context': 1})
def test_implementation(self): environ = DummyEnvironment() info = DummyRendererInfo({ 'name': 'name', }) instance = self._makeOne(info, environ) result = instance.implementation().render({}) self.assertEqual(result, 'result')
def test_no_directories(self): from jinja2.exceptions import TemplateNotFound info = DummyRendererInfo({ 'name': 'helloworld.jinja2', 'package': None, 'registry': self.config.registry, }) renderer = self._callFUT(info) self.assertRaises(TemplateNotFound, lambda: renderer({}, {}))
def test_call(self): environ = DummyEnvironment() info = DummyRendererInfo({ 'name': 'name', }) instance = self._makeOne(info, environ) result = instance({}, {'system': 1}) self.assertTrue(isinstance(result, text_type)) self.assertEqual(result, 'result')
def test_call(self): environ = DummyEnvironment() info = DummyRendererInfo({ 'name': 'name', }) instance = self._makeOne(info, environ) result = instance({}, {'system': 1}) self.failUnless(isinstance(result, unicode)) self.assertEqual(result, u'result')
def test_composite_directories_path(self): from pyramid_jinja2 import IJinja2Environment twice = self.templates_dir + '\n' + self.templates_dir self.config.registry.settings['jinja2.directories'] = twice info = DummyRendererInfo({ 'name': 'helloworld.jinja2', 'package': None, 'registry': self.config.registry, }) self._callFUT(info) environ = self.config.registry.getUtility(IJinja2Environment) self.assertEqual(environ.loader.searchpath, [self.templates_dir] * 2)
def test_with_environ(self): from pyramid_jinja2 import IJinja2Environment environ = dict() self.config.registry.registerUtility(environ, IJinja2Environment) info = DummyRendererInfo({ 'name': 'helloworld.jinja2', 'package': None, 'registry': self.config.registry, }) renderer = self._callFUT(info) self.assertEqual(renderer.environment, environ) self.assertEqual(renderer.info, info)
def test_no_environment(self): from pyramid_jinja2 import IJinja2Environment self.config.registry.settings.update( {'jinja2.directories': self.templates_dir}) info = DummyRendererInfo({ 'name': 'helloworld.jinja2', 'package': None, 'registry': self.config.registry, }) renderer = self._callFUT(info) environ = self.config.registry.getUtility(IJinja2Environment) self.assertEqual(environ.loader.searchpath, [self.templates_dir]) self.assertEqual(renderer.info, info) self.assertEqual(renderer.environment, environ)
def test_with_filters_object(self): from pyramid_jinja2 import IJinja2Environment self.config.registry.settings.update( {'jinja2.directories': self.templates_dir, 'jinja2.filters': {'dummy': dummy_filter}}) info = DummyRendererInfo({ 'name': 'helloworld.jinja2', 'package': None, 'registry': self.config.registry, }) self._callFUT(info) environ = self.config.registry.getUtility(IJinja2Environment) self.assertEqual(environ.filters['dummy'], dummy_filter)