[Subversion] / PEAK / src / peak / web / tests / test_templates.py  

View of /PEAK/src/peak/web/tests/test_templates.py

Parent Directory | Revision Log
Revision: 1275 - (download) (as text)
Mon Jul 21 00:55:16 2003 UTC (20 years, 9 months ago) by pje
File size: 1568 byte(s)
The templates have landed!  We can parse and render templates, and use them
as web methods on locations.  There's even a (yes, just one) unit test.
Big TODO lists both in the package and its test suite, but at least it's
working.  Made minor adjustments to publishing algorithms so that locations
know their parent locations, and methods know the location that they were
found in. Bumped package version to 0.5a3, since we've been in the alpha 3
cycle for a while now.
"""Template tests

TODO

 - Mixed namespaces

 - View property redefinition within a component

 - Security used

 - DOCTYPE
"""

from unittest import TestCase, makeSuite, TestSuite
from peak.api import *
from peak.tests import testRoot
from cStringIO import StringIO


class TestApp(web.SimpleLocation):

    security.allow(
        foo = [security.Anybody],
        bar = [security.Anybody],
        show = [security.Anybody],
    )

    foo = "The title"

    bar = 1,2,3

    show = binding.requireBinding("Template to dump this out with")









class BasicTest(TestCase):

    template = """<body>
<h1 model="foo" view="text">Title Goes Here</h1>
<ul model="bar" view="list">
    <li pattern="listItem" view="text"></li>
</ul>
</body>"""

    rendered = """<body>
<h1>The title</h1>
<ul><li>1</li><li>2</li><li>3</li></ul>
</body>"""

    def setUp(self):
        r = testRoot()
        self.app = TestApp(r, show = self.mkTemplate())
        self.interaction = web.Interaction(r, app = self.app)

    def mkTemplate(self):
        d = web.TemplateDocument(testRoot())
        d.parseFile(StringIO(self.template))
        return d

    def render(self):
        meth = web.LocationPath('show').traverse(
            self.interaction.root, self.interaction
        )
        return self.interaction.callObject(None, meth)


    def checkRendering(self):
        assert self.render() == self.rendered








TestClasses = (
    BasicTest,
)

def test_suite():
    return TestSuite([makeSuite(t,'check') for t in TestClasses])




































cvs-admin@eby-sarna.com

Powered by ViewCVS 1.0-dev

ViewCVS and CVS Help