~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/tests/test_templating.py

  • Committer: Robert Collins
  • Date: 2011-03-14 09:08:14 UTC
  • mfrom: (431.1.1 tests)
  • Revision ID: robertc@robertcollins.net-20110314090814-ks1w4rtlgdqdnshr
Permit running tests via 'make check'.

Show diffs side-by-side

added added

removed removed

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