response = testutil.call(self.root.page_list, tg_paginate_limit=11)
But I got this error:
AttributeError: DummyRequest instance has no attribute
'object_trail'
which comes from the check_app_root function in controllers.py
I then checked out the documentation and discovered call_with_request,
which seemed like what I needed. But I'm not sure how to create a
request. I tried
testutil.create_request(url)
and used cherrypy.request, but I got infinite recursion with this:
testutil.call_with_request(self.root.page_list, cherrypy.request,
tg_paginate_limit=11)
I'm sure I'm not using it properly, but I haven't figured it out and
the docs don't talk about how to create a request object.
Finally, I tried a nasty hack. The method I'm calling has no template
so this:
testutil.create_request(url)
gives me access to cherrypy.request.body[0], which contains the methods
return value in a string, which I can parse. Workable, but I still
have a problem. My input values are not getting through. If I call
this url.
url = '/page_list?tg_paginate_limit=11'
tg_paginate_limit is present in cherrypy.request.params, but is not
available as a keyword in the "decorated" function of paginate.py (line
16). I know it is available in a real application because I've written
some, but for some reason using testutil.create_request doesn't seem to
behave as expected.
Another oddity is when I change the order of the decorators expose and
paginate, paginate doesn't paginate the data.
I'll attach the test if Google Groups allows attachments.
Randall
I put my test controller into a new quickstarted project while
troubleshooting the above and the quickstarted project worked fine.
args and kw was available on paginate.py line 16. Any hints as to why
this doesn't work with testutil.create_request? It must be doing
something differently.
The test controller is very simple:
class MyRoot(tg.controllers.RootController):
def index(self):
return dict()
def page_list(self):
products = makeTestData()
return dict(products=products)
page_list = tg.paginate('products', limit=5)(page_list)
page_list = tg.expose()(page_list)
makeTestData just returns a list of tuples to work with.
Randall
Create a test for paginate.py using turbogears.testutil. Call the
decorated method, passing in tg_paginate_limit and check the number of
results returned. Note that it will work correctly in a quickstarted
project, but not while using testutil.create_request.
Randall
Randall