~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to turbozpt/tests/test_zpt.py

port the few remaining and relevant fixes from annotate.kid to annotate.pt

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
from turbosimpletal import TurboZpt
2
 
from turbogears import controllers, expose, testutil
 
1
from turbozpt import TurboZpt
 
2
from turbogears import controllers
 
3
from turbogears import testutil
 
4
import turbogears
3
5
import cherrypy
4
6
 
5
 
RENDERED = u"<html>\n<head>\n<title>%s</title>\n</head>\n<body>\n<div>Hello, %s</div>\n</body>\n</html>"
 
7
RENDERED="<html>\n<head>\n<title>%s</title>\n</head>\n<body>\n<div>Hello, %s</div>\n</body>\n</html>\n"
6
8
 
7
9
def test_template_lookup():
8
10
    tc = TurboZpt()
9
 
    template = tc.load_template("turbosimpletal.tests.simple")
 
11
    template = tc.load_template("turbozpt.tests.simple")
10
12
    assert template
11
13
    TITLE="test"
12
14
    NAME="World"
13
15
    info = dict(title=TITLE, name=NAME)
14
 
    s = template.expand(**info)
15
 
    assert s.startswith(RENDERED % (TITLE, NAME))
 
16
    t = template(**info)
 
17
    assert str(t).startswith(RENDERED % (TITLE, NAME))
16
18
 
17
19
class TestRoot(controllers.Root):
18
 
    @expose(html="zpt:turbosimpletal.tests.simple")
19
20
    def index(self, name, title="test"):
20
21
        return dict(name=name, title=title)
 
22
    index = turbogears.expose(html="zpt:turbozpt.tests.simple")(index)
21
23
 
22
24
def test_real_life_situation():
23
25
    cherrypy.root = TestRoot()
 
26
    TITLE="test dave"
24
27
    NAME="Dave"
25
28
    testutil.createRequest("/?name=%s" % NAME)
 
29
    print cherrypy.response.body
26
30
    assert cherrypy.response.body[0].startswith(RENDERED % ("test", NAME))