twisted.web.template.Element

Here are the examples of the python api twisted.web.template.Element taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

11 Examples 7

Example 1

Project: SubliminalCollaborator Source File: test_template.py
Function: test_missingtemplateloader
    def test_missingTemplateLoader(self):
        """
        L{Element.render} raises L{MissingTemplateLoader} if the C{loader}
        attribute is C{None}.
        """
        element = Element()
        err = self.assertRaises(MissingTemplateLoader, element.render, None)
        self.assertIdentical(err.element, element)

Example 2

Project: SubliminalCollaborator Source File: test_template.py
    def test_missingRendererMethod(self):
        """
        When called with the name which is not associated with a render method,
        L{Element.lookupRenderMethod} raises L{MissingRenderMethod}.
        """
        element = Element()
        err = self.assertRaises(
            MissingRenderMethod, element.lookupRenderMethod, "foo")
        self.assertIdentical(err.element, element)
        self.assertEqual(err.renderName, "foo")

Example 3

Project: SubliminalCollaborator Source File: test_template.py
Function: test_round_trip
    def test_roundTrip(self):
        """
        Given a series of parsable XML strings, verify that
        L{twisted.web._flatten.flatten} will flatten the L{Element} back to the
        input when sent on a round trip.
        """
        fragments = [
            "<p>Hello, world.</p>",
            "<p><!-- hello, world --></p>",
            "<p><![CDATA[Hello, world.]]></p>",
            '<test1 xmlns:test2="urn:test2">'
                '<test2:test3></test2:test3></test1>',
            '<test1 xmlns="urn:test2"><test3></test3></test1>',
            '<p>\xe2\x98\x83</p>',
        ]
        deferreds = [
            self.assertFlattensTo(Element(loader=XMLString(xml)), xml)
            for xml in fragments]
        return gatherResults(deferreds)

Example 4

Project: SubliminalCollaborator Source File: test_template.py
    def test_entityConversion(self):
        """
        When flattening an HTML entity, it should flatten out to the utf-8
        representation if possible.
        """
        element = Element(loader=XMLString('<p>&#9731;</p>'))
        return self.assertFlattensTo(element, '<p>\xe2\x98\x83</p>')

Example 5

Project: SubliminalCollaborator Source File: test_template.py
Function: test_missingtemplateloader
    def test_missingTemplateLoader(self):
        """
        Rendering a Element without a loader attribute raises the appropriate
        exception.
        """
        return self.assertFlatteningRaises(Element(), MissingTemplateLoader)

Example 6

Project: SubliminalCollaborator Source File: test_template.py
    def test_missingRenderMethod(self):
        """
        Flattening an L{Element} with a C{loader} which has a tag with a render
        directive fails with L{FlattenerError} if there is no available render
        method to satisfy that directive.
        """
        element = Element(loader=XMLString("""
        <p xmlns:t="http://twistedmatrix.com/ns/twisted.web.template/0.1"
          t:render="unknownMethod" />
        """))
        return self.assertFlatteningRaises(element, MissingRenderMethod)

Example 7

Project: SubliminalCollaborator Source File: test_template.py
    def test_transparentRendering(self):
        """
        A C{transparent} element should be eliminated from the DOM and rendered as
        only its children.
        """
        element = Element(loader=XMLString(
            '<t:transparent '
            'xmlns:t="http://twistedmatrix.com/ns/twisted.web.template/0.1">'
            'Hello, world.'
            '</t:transparent>'
        ))
        return self.assertFlattensTo(element, "Hello, world.")

Example 8

Project: SubliminalCollaborator Source File: test_template.py
    def test_attrRendering(self):
        """
        An Element with an attr tag renders the vaule of its attr tag as an
        attribute of its containing tag.
        """
        element = Element(loader=XMLString(
            '<a xmlns:t="http://twistedmatrix.com/ns/twisted.web.template/0.1">'
            '<t:attr name="href">http://example.com</t:attr>'
            'Hello, world.'
            '</a>'
        ))
        return self.assertFlattensTo(element,
            '<a href="http://example.com">Hello, world.</a>')

Example 9

Project: SubliminalCollaborator Source File: test_template.py
    def test_lenientPrefixBehavior(self):
        """
        If the parser sees a prefix it doesn't recognize on an attribute, it
        will pass it on through to serialization.
        """
        theInput = (
            '<hello:world hello:sample="testing" '
            'xmlns:hello="http://made-up.example.com/ns/not-real">'
            'This is a made-up tag.</hello:world>')
        element = Element(loader=XMLString(theInput))
        self.assertFlattensTo(element, theInput)

Example 10

Project: SubliminalCollaborator Source File: test_template.py
    def test_elementContainingStaticElement(self):
        """
        An Element which is returned by the render method of another Element is
        rendered properly.
        """
        class RenderfulElement(Element):
            @renderer
            def renderMethod(self, request, tag):
                return tag(Element(
                    loader=XMLString("<em>Hello, world.</em>")))
        element = RenderfulElement(loader=XMLString("""
        <p xmlns:t="http://twistedmatrix.com/ns/twisted.web.template/0.1"
          t:render="renderMethod" />
        """))
        return self.assertFlattensTo(element, "<p><em>Hello, world.</em></p>")

Example 11

Project: SubliminalCollaborator Source File: test_template.py
Function: test_flatten
    def test_flatten(self):
        """
        L{TagLoader} can be used in an L{Element}, and flattens as the tag used
        to construct the L{TagLoader} would flatten.
        """
        e = Element(self.loader)
        self.assertFlattensImmediately(e, '<i>test</i>')