I put together a simple learning project using 'tg-admin quickstart',
and set up a simple model. Now I want to write a quick-n-dirty python
script to use the model with TestGears. After much skiming of docs and
experimentation, I came up with this:
from sqlobject import *
from turbogears.database import *
connStr = "mysql://mike:[EMAIL PROTECTED]/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!'