Hi Mike,
This is a little easier (and more obvious) in TurboGears 0.9. There's
now a turbogears.database.set_db_uri function you can call to set the
database URI.
You can do the equivalent like this:
cherrypy.config.update({'global':
{"sqlobject.dburi" : dburi}
})
and then you can get rid of all of the hub and connection stuff that
you're doing there.
There's also a DBTest helper class in 0.9.
Kevin
On 12/5/05, Mike Kent <[EMAIL PROTECTED]> wrote:
>
> 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!'
>
>
--
Kevin Dangoor
Author of the Zesty News RSS newsreader
email: [EMAIL PROTECTED]
company: http://www.BlazingThings.com
blog: http://www.BlueSkyOnMars.com