Beispiel #1
0
 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)
Beispiel #2
0
 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})
Beispiel #3
0
 def test_implementation(self):
     environ = DummyEnvironment()
     info = DummyRendererInfo({
         'name': 'name',
     })
     instance = self._makeOne(info, environ)
     result = instance.implementation().render({})
     self.assertEqual(result, 'result')
Beispiel #4
0
 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({}, {}))
Beispiel #5
0
 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')
Beispiel #6
0
 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')
Beispiel #7
0
 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)
Beispiel #8
0
 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)
Beispiel #9
0
 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)
Beispiel #10
0
    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)