from sqlobject import *
from turbogears.database import *
connStr = "mysql://mike:michelle@localhost/books"
conn = connectionForURI(connStr) #Why do I have to do both this...
sqlhub.processConnection = conn
hub = AutoConnectHub(connStr) #...and this, to get it to work.
import books.model
def test_newAuthor():
auth = books.model.Author(last_name="Smith", first_name="John")
assert auth is not None
assert auth.last_name == "Smith"
assert auth.first_name == "John"
This can't really be the right way to do this. Why do I have to use
both 'connnectionForURI()' and 'AutoConnectHub()' to avoid an exception
with a message that ends:
File
"/usr/local/lib/python2.4/site-packages/TurboGears-0.8a5-py2.4.egg/turbogears/database.py",
line 116, in set_hub
raise KeyError, "No database configuration found!"
KeyError: 'No database configuration found!'
but I think it is not very good to do so, model.py depend on the
cherrypy runtime.
the program is hard to test and run without cherrypy.
so the best way is that model.py is separated from cherrypy's
config.Do you think so?
Technically, you don't *have* to use CherryPy's config module in this
instance. You can instantiate your own AutoConnectHub with a URI for
the database connection you want.
The config mechanism for all of TurboGears is CherryPy's. I don't see
a need to grow our own independent config system or to have one config
for the model and other config files for other things. Is there some
other separation you'd envision?
I also don't think that using CP's config system in any way breaks the
MVC separation.
Kevin