unit testing: testutil usage issues

2 weergaven
Naar het eerste ongelezen bericht

Max Ischenko

ongelezen,
26 sep 2006, 03:08:1326-09-2006
aan 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

ongelezen,
29 sep 2006, 16:54:1629-09-2006
aan 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
Allen beantwoorden
Auteur beantwoorden
Doorsturen
0 nieuwe berichten