unit testing: testutil usage issues

2 views
Skip to first unread message

Max Ischenko

unread,
Sep 26, 2006, 3:08:13 AM9/26/06
to turbo...@googlegroups.com
Hi,

Is it just me who struggle trying to unit-test TG code?

As it is, to be able to unit test my code that calls turbogears.url I need the following setup:

    import cherrypy, turbogears
    from spaca.controllers import Root
    turbogears.config.update({'visit.on':True})
    cherrypy.root = Root()
    from turbogears.testutil import DummyRequest
    cherrypy.request = DummyRequest()
    cherrypy.request.app_root = ''

Plus it spews a lot of garbage to console.

Is there a way to do unit testing with less headache? May be I miss something?

Explanation:

1. Simply attempt to import testutil yields:

  File "D:\Projects\Spaca\spaca\tests\test_model.py", line 50, in test_resource_
action_link                                                                    
    from turbogears.testutil import DummyRequest                               
  File "c:\python24\lib\site-packages\TurboGears-1.0b1-py2.4.egg\turbogears\test
util.py", line 23, in ?                                                        
    cherrypy.server.start(serverClass=None, initOnly=True)                     
....
    raise IdentityConfigurationException( "Visit tracking must be enabled (visit
.on)" )                                                                        
IdentityConfigurationException: Visit tracking must be enabled (visit.on)      

2. Adding     turbogears.config.update({'visit.on':True}) yields:

    from turbogears.testutil import DummyRequest                               
  File "c:\python24\lib\site-packages\TurboGears-1.0b1-py2.4.egg\turbogears\test
util.py", line 23, in ?                                                        
    cherrypy.server.start(serverClass=None, initOnly=True)                     
....                        
    cherrypy.root._cp_filters= []                                              
AttributeError: 'NoneType' object has no attribute '_cp_filters'               

--
Best regards, Max
http://maxischenko.in.ua/
http://www.developers.org.ua/

Kevin Dangoor

unread,
Sep 29, 2006, 4:54:16 PM9/29/06
to turbo...@googlegroups.com
Hi Max,

You're right, that is a lot of boilerplate. Maybe if there was a function in testutil to set up the environment for you (just does those things...it should be able to find the top of the project so that it can track down your Root).

Kevin
Reply all
Reply to author
Forward
0 new messages