Ejemplo n.º 1
0
 def test_synchronousFlatten(self):
     """
     Flattening a L{Element} with no Deferreds using the old synchronous
     flattener API returns a value synchronously.
     """
     element = Element()
     element.docFactory = stan(["hello, world"])
     self.assertEqual(synchronousFlatten(element), "hello, world")
Ejemplo n.º 2
0
 def test_synchronousFlatten(self):
     """
     Flattening a L{Element} with no Deferreds using the old synchronous
     flattener API returns a value synchronously.
     """
     element = Element()
     element.docFactory = stan(["hello, world"])
     self.assertEqual(synchronousFlatten(element), "hello, world")
Ejemplo n.º 3
0
 def test_synchronousFlattenError(self):
     """
     If the old flattener encounters an exception while flattening an
     L{IRenderable}, the exception is raised to the caller of the flattener
     API.
     """
     element = Element()
     element.docFactory = stan(invisible(render=directive('foo')))
     self.assertRaises(FlattenerError, synchronousFlatten, element)
Ejemplo n.º 4
0
 def test_synchronousFlattenError(self):
     """
     If the old flattener encounters an exception while flattening an
     L{IRenderable}, the exception is raised to the caller of the flattener
     API.
     """
     element = Element()
     element.docFactory = stan(invisible(render=directive('foo')))
     self.assertRaises(FlattenerError, synchronousFlatten, element)
Ejemplo n.º 5
0
 def test_flattenable(self):
     """
     Flattening L{Element} instances with the new flatten function results in
     the flattened version of whatever their C{render} method returns.
     """
     element = Element()
     element.docFactory = stan(["Hello, world"])
     result = []
     finished = newFlatten(FakeRequest(), element, False, False, result.append)
     finished.addCallback(lambda ignored: "".join(result))
     finished.addCallback(self.assertEqual, "Hello, world")
     return finished
Ejemplo n.º 6
0
 def test_oldFlattenable(self):
     """
     Flattening L{Element} instances with the old flatten function results in
     the flattened version of whatever their C{render} method returns.
     """
     result = []
     element = Element()
     element.docFactory = stan(['"&<>'])
     request = FakeRequest()
     context = WovenContext()
     context.remember(request)
     finished = oldFlatten(element, context, result.append, lambda ign: ign)
     finished.addCallback(lambda ign: "".join(result))
     finished.addCallback(self.assertEqual, '"&amp;&lt;&gt;')
     return finished
Ejemplo n.º 7
0
 def test_oldFlattenableInAttribute(self):
     """
     Flattening a L{Element} as the value of an attribute of a L{Tag} XML
     attribute escapes the element's flattened document.
     """
     result = []
     element = Element()
     element.docFactory = stan(['"&<>'])
     request = FakeRequest()
     context = WovenContext()
     context.remember(request)
     finished = oldFlatten(p(foo=element), context, result.append, lambda ign: ign)
     finished.addCallback(lambda ign: "".join(result))
     finished.addCallback(self.assertEqual, '<p foo="&quot;&amp;&lt;&gt;"></p>')
     return finished
Ejemplo n.º 8
0
 def test_oldFlattenable(self):
     """
     Flattening L{Element} instances with the old flatten function results in
     the flattened version of whatever their C{render} method returns.
     """
     result = []
     element = Element()
     element.docFactory = stan(['"&<>'])
     request = FakeRequest()
     context = WovenContext()
     context.remember(request)
     finished = oldFlatten(element, context, result.append, lambda ign: ign)
     finished.addCallback(lambda ign: "".join(result))
     finished.addCallback(self.assertEqual, '"&amp;&lt;&gt;')
     return finished
Ejemplo n.º 9
0
    def test_render(self):
        """
        L{Element.render} loads a document from the C{docFactory} attribute and
        returns it.
        """
        args = []
        preproc = object()
        class DocFactory(object):
            def load(self, ctx, preprocessors, precompile=None):
                args.append(preprocessors)
                return "result"

        element = Element()
        element.preprocessors = (preproc,)
        element.docFactory = DocFactory()
        self.assertEqual(element.render(None), "result")
        self.assertEqual(args, [(preproc,)])
Ejemplo n.º 10
0
    def test_oldFlattenableError(self):
        """
        If the old flattener encounters an asynchronous Failure while
        flattening an L{IRenderable}, the returned L{Deferred} fires with the
        failure.
        """
        result = Deferred()
        element = Element()
        element.docFactory = stan(result)

        request = FakeRequest()
        context = WovenContext()
        context.remember(request)

        accumulator = []
        finished = oldFlatten(element, context, accumulator.append, lambda ign: ign)
        result.addErrback(lambda err: err.trap(RuntimeError))
        finished = self.assertFailure(finished, RuntimeError)
        result.errback(RuntimeError("test error"))
        return finished