unit testing: testutil usage issues

2 vues
Accéder directement au premier message non lu

Max Ischenko

non lue,
26 sept. 2006, 03:08:1326/09/2006
à 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

non lue,
29 sept. 2006, 16:54:1629/09/2006
à 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
Répondre à tous
Répondre à l'auteur
Transférer
0 nouveau message