Hope someone can help me out. I've been trying to get functional tests
going with twill, and have managed to figure out how to get everything
working except for verifying against my model.
I do want to manually set everything in this code, both to better
understand what's going on, and to ensure a specific environment with
regards to session vars, port, and db, hence all the manual stuff in the
module level setup function. I get the dreaded dictionary empty
traceback as soon as I try to use the model. Here is the test code, any
clues would be most appreciated!
import cherrypy
from tdtg.controllers import Root
import twill
from twill.commands import *
from twill import get_browser
from StringIO import StringIO
# manual bring in the model and the sa engine
import sqlalchemy as sa
db = sa.create_engine('mysql://web:[EMAIL PROTECTED]/tdtg_db_test')
metadata = sa.MetaData(db)
from tdtg.model import Product
# cp configs, same values as in the tg config files
test_config = {
"server.environment":"production",
"server.socket_port":9080,
"server.logToScreen":False,
"session_filter.on":True,
}
# use module level setup/teardown to start/stop server
# by starting the server anew, we clear all session vars
def setup():
print "module level setup()"
# fire up the server
cherrypy.root = Root()
cherrypy.config.update( test_config )
cherrypy.server.start( initOnly=True )
# wipe and recreate the tables
metadata.drop_all()
metadata.create_all()
# start off on main url
go("http://localhost:9080")
def teardown():
print "module level teardown()"
cherrypy.server.stop()
def test1():
'find Home using twill commands'
go('home')
code(200)
find('Home')
# this one kills it all!
def test2():
'verify 1 product in the test db'
products = Product.select()
assert len(products)==1
And the Traceback:
======================================================================
ERROR: verify 1 product in the test db
----------------------------------------------------------------------
Traceback (most recent call last):
File
"/usr/lib/python2.4/site-packages/nose-0.10.0a1-py2.4.egg/nose/case.py",
line 178, in runTest
self.test(*self.arg)
File "/home/xornot/www/tdtg/tdtg/tests/test_twill_funct.py", line 49,
in test3
products = Product.select()
File
"/usr/lib/python2.4/site-packages/SQLAlchemy-0.3.11-py2.4.egg/sqlalchemy/ext/assignmapper.py",
line 6, in do
query = Query(class_, session=ctx.current)
File
"/usr/lib/python2.4/site-packages/SQLAlchemy-0.3.11-py2.4.egg/sqlalchemy/ext/sessioncontext.py",
line 32, in get_current
return self.registry()
File
"/usr/lib/python2.4/site-packages/SQLAlchemy-0.3.11-py2.4.egg/sqlalchemy/util.py",
line 484, in __call__
return self.registry.setdefault(key, self.createfunc())
File
"/usr/lib/python2.4/site-packages/TurboGears-1.0.3.2-py2.4.egg/turbogears/database.py",
line 57, in create_session
bind_meta_data()
File
"/usr/lib/python2.4/site-packages/TurboGears-1.0.3.2-py2.4.egg/turbogears/database.py",
line 66, in bind_meta_data
get_engine()
File
"/usr/lib/python2.4/site-packages/TurboGears-1.0.3.2-py2.4.egg/turbogears/database.py",
line 42, in get_engine
dburi = alch_args.pop('dburi')
KeyError: 'pop(): dictionary is empty'
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TurboGears" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/turbogears?hl=en
-~----------~----~----~----~------~----~------~--~---