I am so confused on this one. I use AutoconnectHub to set the
_connection attribute of a SQLObject class (call it modelroot), which
is inheritable. I then have a bunch of other SQLObject classes which
inherit from modelroot. Now, everything works fine when I run the the
turbogears server normally - that is, all my derived classes properly
inherit the _connection and connect to the database without a hitch.
So I've now tried to create unit tests for the derived classes. In
those tests (which derive from unittest), I set the connection in the
setUp() method. Problem is, no matter how I try and set the
connection, I get this:
Traceback (most recent call last):
File
"/usr/home/ppetrick/repos/lab_manager/trunk/dev/server/server_core/core/tests/unit/test_group.py",
line 20, in setUp
self.dropTables()
File
"/usr/home/ppetrick/repos/lab_manager/trunk/dev/server/server_core/core/tests/unit/test_group.py",
line 25, in dropTables
User.dropTable(ifExists=True)
File
"/usr/local/lib/python2.4/site-packages/SQLObject-0.7.0-py2.4.egg/sqlobject/main.py",
line 1294, in dropTable
conn = connection or cls._connection
File
"/usr/local/lib/python2.4/site-packages/SQLObject-0.7.0-py2.4.egg/sqlobject/dbconnection.py",
line 848, in __get__
return self.getConnection()
File
"/usr/local/lib/python2.4/site-packages/TurboGears-0.8a4-py2.4.egg/turbogears/database.py",
line 36, in getConnection
raise AttributeError(
AttributeError: No connection has been defined for this thread or
process
I've used the following lines to try and set up the connection in the
setUp() routines (where db_connection holds the database uri and hub is
set to AutoConnectHub()):
from sqlobject import *
from turbogears.database import *
sqlhub.processConnection = connectionForURI(db_connection)
sqlhub.threadConnection = connectionForURI(db_connection)
hub.processConnection = connectionForURI(db_connection)
hub.threadConnection = connectionForURI(db_connection)
database.set_db_uri(db_connection)
It's the same error every time. What the heck am I doing wrong?
Also, what is the most "correct" way to do this?