TG2 testutils module

0 views
Skip to first unread message

Ryan Petrello

unread,
Jan 2, 2008, 4:57:52 PM1/2/08
to TurboGears Trunk
On a recent project, I've found the need for some more powerful unit
testing capabilities in TG2.

Currently, the only way that I've found of going about unit testing in
TG2 is to use paste.fixture and Pylon's TestController
(http://wiki.pylonshq.com/pages/viewpage.action?pageId=9011209).

It seems that this solution really only returns the results of a
controller after they've been rendered into appropriate templates,
however. In lots of instances, it would be desirable to actually call
a specific controller or URL and retrieve Python objects. Another
option is JSON, but this is somewhat limited in that many items are
not convertible into JSON (imagine situations where you have
controllers that return SQLAlchemy results, or any other class which
doesn't have a defined conversion to JSON). This sort of
functionality was available in TG1:

http://svn.turbogears.org/branches/1.1/turbogears/testutil.py

...but it appears that it does not yet exist in TG2. I'd like to
suggest adding this functionality to TG2 (and would like to develop a
patch for it).

Any ideas/thoughts/suggestions?

Ian Bicking

unread,
Jan 2, 2008, 5:59:40 PM1/2/08
to turbogea...@googlegroups.com

The equivalent in Pylons in resp.c (which gives the values from
pylons.c). If TG is not putting any return values in the response, then
it should. If you have custom values, you can put them in
req.environ['paste.testing_variables'] and they show up as attributes on
the response object (if that key exists in the environ; if it doesn't
then it's not a test request).


--
Ian Bicking : ia...@colorstudy.com : http://blog.ianbicking.org

Mark Ramm

unread,
Jan 2, 2008, 9:39:46 PM1/2/08
to turbogea...@googlegroups.com
> The equivalent in Pylons in resp.c (which gives the values from
> pylons.c). If TG is not putting any return values in the response, then
> it should. If you have custom values, you can put them in
> req.environ['paste.testing_variables'] and they show up as attributes on
> the response object (if that key exists in the environ; if it doesn't
> then it's not a test request).

I've send in a hg bundle which will expose the variables we put into
the template namespace under resp.namespace.

--Mark

Reply all
Reply to author
Forward
0 new messages