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

On Sep 26, 2006, at 3:08 AM, Max Ischenko wrote:

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/

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/turbogears
-~----------~----~----~----~------~----~------~--~---

Reply via email to