def test_find__template_path(self):
     """Test _find() with TemplateSpec.template_path."""
     loader = self._make_specloader()
     custom = TemplateSpec()
     custom.template_path = "path/foo"
     actual = loader._find(custom)
     self.assertPaths(actual, "path/foo")
Beispiel #2
0
    def test_load__template__correct_loader(self):
        """
        Test that reader.unicode() is called correctly.

        This test tests that the correct reader is called with the correct
        arguments.  This is a catch-all test to supplement the other
        test cases.  It tests SpecLoader.load() independent of reader.unicode()
        being implemented correctly (and tested).

        """
        class MockLoader(Loader):
            def __init__(self):
                self.s = None
                self.encoding = None

            # Overrides the existing method.
            def unicode(self, s, encoding=None):
                self.s = s
                self.encoding = encoding
                return u"foo"

        loader = MockLoader()
        custom_loader = SpecLoader()
        custom_loader.loader = loader

        view = TemplateSpec()
        view.template = "template-foo"
        view.template_encoding = "encoding-foo"

        # Check that our unicode() above was called.
        self._assert_template(custom_loader, view, u'foo')
        self.assertEqual(loader.s, "template-foo")
        self.assertEqual(loader.encoding, "encoding-foo")
Beispiel #3
0
 def test_find__template_path(self):
     """Test _find() with TemplateSpec.template_path."""
     loader = self._make_specloader()
     custom = TemplateSpec()
     custom.template_path = "path/foo"
     actual = loader._find(custom)
     self.assertPaths(actual, "path/foo")
    def test_load__template__correct_loader(self):
        """
        Test that reader.unicode() is called correctly.

        This test tests that the correct reader is called with the correct
        arguments.  This is a catch-all test to supplement the other
        test cases.  It tests SpecLoader.load() independent of reader.unicode()
        being implemented correctly (and tested).

        """
        class MockLoader(Loader):

            def __init__(self):
                self.s = None
                self.encoding = None

            # Overrides the existing method.
            def unicode(self, s, encoding=None):
                self.s = s
                self.encoding = encoding
                return u"foo"

        loader = MockLoader()
        custom_loader = SpecLoader()
        custom_loader.loader = loader

        view = TemplateSpec()
        view.template = "template-foo"
        view.template_encoding = "encoding-foo"

        # Check that our unicode() above was called.
        self._assert_template(custom_loader, view, u'foo')
        self.assertEqual(loader.s, "template-foo")
        self.assertEqual(loader.encoding, "encoding-foo")
Beispiel #5
0
 def __init__(self, graph, desc, params, cookie, agent,
              openidProxyHeader, forwardedFor):
     TemplateSpec.__init__(self)
     self.graph = graph
     self.desc = desc
     self.params, self.cookie, self.agent = params, cookie, agent
     self.openidProxyHeader = openidProxyHeader
     self.forwardedFor = forwardedFor
Beispiel #6
0
 def __init__(self, graph, desc, params, cookie, agent, openidProxyHeader,
              forwardedFor):
     TemplateSpec.__init__(self)
     self.graph = graph
     self.desc = desc
     self.params, self.cookie, self.agent = params, cookie, agent
     self.openidProxyHeader = openidProxyHeader
     self.forwardedFor = forwardedFor
Beispiel #7
0
    def test_load__template__unicode_non_ascii(self):
        """
        Test the template attribute: non-ascii unicode string.

        """
        custom = TemplateSpec()
        custom.template = u"é"

        self._assert_template(SpecLoader(), custom, u"é")
Beispiel #8
0
    def test_load__template__type_unicode(self):
        """
        Test the template attribute: unicode string.

        """
        custom = TemplateSpec()
        custom.template = u"abc"

        self._assert_template(SpecLoader(), custom, u"abc")
Beispiel #9
0
    def test_load__template__unicode_non_ascii(self):
        """
        Test the template attribute: non-ascii unicode string.

        """
        custom = TemplateSpec()
        custom.template = "é"

        spec_loader = self._make_specloader()
        self._assert_template(spec_loader, custom, "é")
    def test_load__template__type_str(self):
        """
        Test the template attribute: str string.

        """
        custom = TemplateSpec()
        custom.template = "abc"

        spec_loader = self._make_specloader()
        self._assert_template(spec_loader, custom, u"abc")
Beispiel #11
0
    def test_load__template__unicode_non_ascii(self):
        """
        Test the template attribute: non-ascii unicode string.

        """
        custom = TemplateSpec()
        custom.template = u"é"

        spec_loader = self._make_specloader()
        self._assert_template(spec_loader, custom, u"é")
Beispiel #12
0
    def test_load__template__type_unicode(self):
        """
        Test the template attribute: unicode string.

        """
        custom = TemplateSpec()
        custom.template = u"abc"

        spec_loader = self._make_specloader()
        self._assert_template(spec_loader, custom, u"abc")
Beispiel #13
0
    def test_load__template__with_template_encoding(self):
        """
        Test the template attribute: with template encoding attribute.

        """
        custom = TemplateSpec()
        custom.template = u'é'.encode('utf-8')

        self.assertRaises(UnicodeDecodeError, self._assert_template, SpecLoader(), custom, u'é')

        custom.template_encoding = 'utf-8'
        self._assert_template(SpecLoader(), custom, u'é')
Beispiel #14
0
    def test_load__template__with_template_encoding(self):
        """
        Test the template attribute: with template encoding attribute.

        """
        custom = TemplateSpec()
        custom.template = u'é'.encode('utf-8')

        spec_loader = self._make_specloader()

        self.assertRaises(UnicodeDecodeError, self._assert_template, spec_loader, custom, u'é')

        custom.template_encoding = 'utf-8'
        self._assert_template(spec_loader, custom, u'é')
Beispiel #15
0
    def test_load__template__with_template_encoding(self):
        """
        Test the template attribute: with template encoding attribute.

        """
        custom = TemplateSpec()
        custom.template_encoding = 'ascii'
        custom.template = 'é'.encode('utf-8')

        spec_loader = self._make_specloader()

        self.assertRaises(UnicodeDecodeError, self._assert_template, spec_loader, custom, 'é')

        custom.template_encoding = 'utf-8'
        self._assert_template(spec_loader, custom, 'é')
    def test_template_path_for_partials(self):
        """
        Test that View.template_rel_path is respected for partials.

        """
        spec = TemplateSpec()
        spec.template = "Partial: {{>tagless}}"

        renderer1 = Renderer()
        renderer2 = Renderer(search_dirs=EXAMPLES_DIR)

        self.assertRaises(IOError, renderer1.render, spec)

        actual = renderer2.render(spec)
        self.assertEqual(actual, "Partial: No tags...")
Beispiel #17
0
    def test_template_path_for_partials(self):
        """
        Test that View.template_rel_path is respected for partials.

        """
        spec = TemplateSpec()
        spec.template = "Partial: {{>tagless}}"

        renderer1 = Renderer()
        renderer2 = Renderer(search_dirs=EXAMPLES_DIR)

        actual = renderer1.render(spec)
        self.assertString(actual, u"Partial: ")

        actual = renderer2.render(spec)
        self.assertEqual(actual, "Partial: No tags...")