Testing Issues with decorated method

0 views
Skip to first unread message

Randall

unread,
Oct 24, 2006, 5:20:35 PM10/24/06
to TurboGears
I'm creating tests for paginate.py. Initially, I wanted to call
methods directly like so:

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

Randall

unread,
Oct 25, 2006, 4:15:36 PM10/25/06
to TurboGears
Randall wrote:
> 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.

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

Randall

unread,
Oct 25, 2006, 10:34:32 PM10/25/06
to TurboGears
I haven't made any progress yet and I need to move on to something
else. If you've read this thread and the problem is not clear, just do
this and you'll see.

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

unread,
Nov 2, 2006, 1:13:27 PM11/2/06
to TurboGears
I really would like to write tests for paginate.py. Will someone with
experience with testutil please help me on this issue?

Randall

Reply all
Reply to author
Forward
0 new messages