Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #2243 (closed defect: fixed)

Opened 10 years ago

Last modified 10 years ago

Regression: SQLAlchemy is not properly set up in test environments

Reported by: Gustavo Owned by:
Priority: highest Milestone: 2.0rc1
Component: TurboGears Version: trunk
Severity: blocker Keywords:
Cc:

Description

To reproduce the bug, copy/paste the following method of RootController:

    @expose('authproj.templates.index')
    def show_email(self, userid):
        user = model.User.by_user_name(userid)
        flash('The email address is: %s' % user.email_address)
        return dict(page='email')

Next, test it with the following code:

    def test_email(self):
        # Adding the user:
        manager = User(user_name=u'manager', email_address=u'manager@somedomain.com')
        DBSession.add(manager)
        DBSession.flush()
        # Checking that it works:
        resp = self.app.get('/show_email/manager', status=200)
        assert "The email address is: manager@somedomain.com" in resp.body, resp.body

The result?

ERROR: authproj.tests.functional.test_authentication.TestAuthentication.test_email                                                                                        
----------------------------------------------------------------------                                                                                                    
Traceback (most recent call last):                                                                                                                                        
  File "/home/gustavo/System/Pyenvs/tg2/lib/python2.6/site-packages/nose-0.10.4-py2.6.egg/nose/case.py", line 182, in runTest                                             
    self.test(*self.arg)                                                                                                                                                  
  File "/home/gustavo/Projeti/TurboGears/FakeProjects/authproj/authproj/tests/functional/test_authentication.py", line 14, in test_email                                  
    resp = self.app.get('/show_email/manager', status=200)                                                                                                                
  File "build/bdist.linux-i686/egg/webtest/__init__.py", line 148, in get                                                                                                 
  File "build/bdist.linux-i686/egg/webtest/__init__.py", line 306, in do_request                                                                                          
  File "build/bdist.linux-i686/egg/webob/__init__.py", line 1321, in get_response                                                                                         
  File "build/bdist.linux-i686/egg/webob/__init__.py", line 1293, in call_application                                                                                     
  File "build/bdist.linux-i686/egg/webtest/lint.py", line 170, in lint_app                                                                                                
    iterator = application(environ, start_response_wrapper)                                                                                                               
  File "/home/gustavo/System/Pyenvs/tg2/lib/python2.6/site-packages/Paste-1.7.2-py2.6.egg/paste/cascade.py", line 130, in __call__                                        
    return self.apps[-1](environ, start_response)                                                                                                                         
  File "/home/gustavo/System/Pyenvs/tg2/lib/python2.6/site-packages/Paste-1.7.2-py2.6.egg/paste/registry.py", line 350, in __call__                                       
    app_iter = self.application(environ, start_response)                                                                                                                  
  File "/home/gustavo/System/Pyenvs/tg2/lib/python2.6/site-packages/Pylons-0.9.7-py2.6.egg/pylons/middleware.py", line 201, in __call__                                   
    self.app, environ, catch_exc_info=True)                                                                                                                               
  File "/home/gustavo/System/Pyenvs/tg2/lib/python2.6/site-packages/Pylons-0.9.7-py2.6.egg/pylons/util.py", line 94, in call_wsgi_application                             
    app_iter = application(environ, start_response)                                                                                                                       
  File "/home/gustavo/System/Pyenvs/tg2/lib/python2.6/site-packages/WebError-0.10.1-py2.6.egg/weberror/evalexception.py", line 235, in __call__                           
    return self.respond(environ, start_response)                                                                                                                          
  File "/home/gustavo/System/Pyenvs/tg2/lib/python2.6/site-packages/WebError-0.10.1-py2.6.egg/weberror/evalexception.py", line 418, in respond                            
    return self.application(environ, start_response)                                                                                                                      
  File "/home/gustavo/Projeti/TurboGears/TG2/tg/configuration.py", line 631, in wrapper                                                                                   
    return app(environ, start_response)                                                                                                                                   
  File "/home/gustavo/Projeti/TurboGears/TG2/tg/configuration.py", line 534, in remover                                                                                   
    return app(environ, start_response)                                                                                                                                   
  File "/home/gustavo/System/Pyenvs/tg2/lib/python2.6/site-packages/repoze.tm2-1.0a3-py2.6.egg/repoze/tm/__init__.py", line 19, in __call__                               
    result = self.application(environ, save_status_and_headers)                                                                                                           
  File "/home/gustavo/System/Pyenvs/tg2/lib/python2.6/site-packages/repoze.who-1.0.10-py2.6.egg/repoze/who/middleware.py", line 107, in __call__                          
    app_iter = app(environ, wrapper.wrap_start_response)                                                                                                                  
  File "/home/gustavo/System/Pyenvs/tg2/lib/python2.6/site-packages/ToscaWidgets-0.9.5dev_20081026-py2.6.egg/tw/core/middleware.py", line 36, in __call__                 
    return self.wsgi_app(environ, start_response)                                                                                                                         
  File "/home/gustavo/System/Pyenvs/tg2/lib/python2.6/site-packages/ToscaWidgets-0.9.5dev_20081026-py2.6.egg/tw/core/middleware.py", line 59, in wsgi_app                 
    resp = req.get_response(self.application)                                                                                                                             
  File "build/bdist.linux-i686/egg/webob/__init__.py", line 1325, in get_response                                                                                         
  File "build/bdist.linux-i686/egg/webob/__init__.py", line 1293, in call_application                                                                                     
  File "/home/gustavo/System/Pyenvs/tg2/lib/python2.6/site-packages/ToscaWidgets-0.9.5dev_20081026-py2.6.egg/tw/core/resource_injector.py", line 67, in _injector         
    resp = req.get_response(app)                                                                                                                                          
  File "build/bdist.linux-i686/egg/webob/__init__.py", line 1325, in get_response                                                                                         
  File "build/bdist.linux-i686/egg/webob/__init__.py", line 1293, in call_application                                                                                     
  File "/home/gustavo/System/Pyenvs/tg2/lib/python2.6/site-packages/Beaker-1.2.2-py2.6.egg/beaker/middleware.py", line 81, in __call__                                    
    return self.app(environ, start_response)                                                                                                                              
  File "/home/gustavo/System/Pyenvs/tg2/lib/python2.6/site-packages/Beaker-1.2.2-py2.6.egg/beaker/middleware.py", line 160, in __call__                                   
    return self.wrap_app(environ, session_start_response)                                                                                                                 
  File "/home/gustavo/System/Pyenvs/tg2/lib/python2.6/site-packages/Routes-1.10.3-py2.6.egg/routes/middleware.py", line 130, in __call__                                  
    response = self.app(environ, start_response)                                                                                                                          
  File "/home/gustavo/System/Pyenvs/tg2/lib/python2.6/site-packages/Pylons-0.9.7-py2.6.egg/pylons/wsgiapp.py", line 125, in __call__                                      
    response = self.dispatch(controller, environ, start_response)                                                                                                         
  File "/home/gustavo/System/Pyenvs/tg2/lib/python2.6/site-packages/Pylons-0.9.7-py2.6.egg/pylons/wsgiapp.py", line 324, in dispatch                                      
    return controller(environ, start_response)                                                                                                                            
  File "/home/gustavo/Projeti/TurboGears/FakeProjects/authproj/authproj/lib/base.py", line 36, in __call__                                                                
    return TGController.__call__(self, environ, start_response)                                                                                                           
  File "/home/gustavo/System/Pyenvs/tg2/lib/python2.6/site-packages/Pylons-0.9.7-py2.6.egg/pylons/controllers/core.py", line 221, in __call__                             
    response = self._dispatch_call()                                                                                                                                      
  File "/home/gustavo/System/Pyenvs/tg2/lib/python2.6/site-packages/Pylons-0.9.7-py2.6.egg/pylons/controllers/core.py", line 172, in _dispatch_call                       
    response = self._inspect_call(func)                                                                                                                                   
  File "/home/gustavo/System/Pyenvs/tg2/lib/python2.6/site-packages/Pylons-0.9.7-py2.6.egg/pylons/controllers/core.py", line 107, in _inspect_call                        
    result = self._perform_call(func, args)                                                                                                                               
  File "/home/gustavo/Projeti/TurboGears/TG2/tg/controllers.py", line 745, in _perform_call                                                                               
    self, controller, params, remainder=remainder)                                                                                                                        
  File "/home/gustavo/Projeti/TurboGears/TG2/tg/controllers.py", line 137, in _perform_call                                                                               
    output = controller(*remainder, **dict(params))                                                                                                                       
  File "/home/gustavo/Projeti/TurboGears/FakeProjects/authproj/authproj/controllers/root.py", line 66, in show_email                                                      
    flash('The email address is: %s' % user.email_address)                                                                                                                
AttributeError: 'NoneType' object has no attribute 'email_address'

This bug is also present in TG 2.0b5, when it was not necessary to add the user manually because "paster setup-app ..." was run.

I'll also attach a test case which verifies that the same bug occurs at the middleware level (on ingress).

Attachments

test_authentication.py Download (2.5 KB) - added by Gustavo 10 years ago.
The bug is present on ingress too

Change History

Changed 10 years ago by Gustavo

The bug is present on ingress too

comment:1 Changed 10 years ago by Gustavo

  • Status changed from new to closed
  • Resolution set to fixed

Unconsciously fixed in [6468].

#2259 may be related.

Note: See TracTickets for help on using tickets.