Hello, I'm trying to write some tests for my code, which uses SQLAlchemy and Elixir as ORM. I have the following code on my test_controllers.py, that I got from a paste in the paste bin by Christopher Arndt:
=================================================================== import turbogears from nose import with_setup from turbogears import database, testutil import sqlalchemy from turbogears.util import get_model from pymeter.controllers import Root import cherrypy from pymeter import model cherrypy.root = Root() # got this class from http://paste.turbogears.org/paste/950; thanks to # Christopher Arndt class SADBTest(object): model = None def setUp(self): # bind metadata/engine to model database.bind_meta_data() if not self.model: self.model = get_model() if not self.model: raise "Unable to run database tests without a model" # create all model tables for item in dir(self.model): item = getattr(self.model, item) if isinstance(item, sqlalchemy.Table): item.create(checkfirst=True) def tearDown(self): database.rollback_all() # drop all model tables for item in dir(self.model): item = getattr(self.model, item) if isinstance(item, sqlalchemy.Table): item.drop(checkfirst=True) class test_collector_functionality(SADBTest): model = model def test_add_first_system(self): testutil.createRequest('/pymeter/system/') assert 'id="systems" class="grid">' not in cherrypy.response.body[0] def test_add_and_list_systems(self): import pdb;pdb.set_trace() self.setUp() obj = model.System(name='lala', host='www.debian.org', port=80, base_url='/') obj.flush() assert model.System.get(1).name == 'lala' =================================================================== My test.cfg is only one line: =================================================================== sqlalchemy.dburi = "sqlite:///:memory:" =================================================================== When I run nose I have this problem: =================================================================== Traceback (most recent call last): File "/var/lib/python-support/python2.4/nose/case.py", line 132, in runTest self.testCase(*self.arg) File "/home/kov/src/pymeter/trunk/pymeter/tests/test_controllers.py", line 51, in test_add_and_list_systems obj.flush() File "/usr/lib/python2.4/site-packages/sqlalchemy/ext/assignmapper.py", line 16, in do return getattr(session, name)(self, *args, **kwargs) File "/usr/lib/python2.4/site-packages/sqlalchemy/orm/session.py", line 220, in flush self.uow.flush(self, objects) File "/usr/lib/python2.4/site-packages/sqlalchemy/orm/unitofwork.py", line 194, in flush flush_context.execute() File "/usr/lib/python2.4/site-packages/sqlalchemy/orm/unitofwork.py", line 333, in execute head.execute(self) File "/usr/lib/python2.4/site-packages/sqlalchemy/orm/unitofwork.py", line 470, in execute UOWExecutor().execute(trans, self) File "/usr/lib/python2.4/site-packages/sqlalchemy/orm/unitofwork.py", line 793, in execute self.execute_save_steps(trans, task) File "/usr/lib/python2.4/site-packages/sqlalchemy/orm/unitofwork.py", line 810, in execute_save_steps self.save_objects(trans, task) File "/usr/lib/python2.4/site-packages/sqlalchemy/orm/unitofwork.py", line 798, in save_objects task._save_objects(trans) File "/usr/lib/python2.4/site-packages/sqlalchemy/orm/unitofwork.py", line 461, in _save_objects self.mapper.save_obj(self.polymorphic_tosave_objects, trans) File "/usr/lib/python2.4/site-packages/sqlalchemy/orm/mapper.py", line 998, in save_obj c = connection.execute(statement, params) File "/usr/lib/python2.4/site-packages/sqlalchemy/engine/base.py", line 258, in execute return Connection.executors[type(object).__mro__[-2]](self, object, *multiparams, **params) File "/usr/lib/python2.4/site-packages/sqlalchemy/engine/base.py", line 282, in execute_clauseelement return self.execute_compiled(elem.compile(engine=self.__engine, parameters=param), *multiparams, **params) File "/usr/lib/python2.4/site-packages/sqlalchemy/engine/base.py", line 298, in execute_compiled proxy(str(compiled), parameters) File "/usr/lib/python2.4/site-packages/sqlalchemy/engine/base.py", line 294, in proxy self._execute_raw(statement, parameters, cursor=cursor, context=context) File "/usr/lib/python2.4/site-packages/sqlalchemy/engine/base.py", line 332, in _execute_raw self._execute(cursor, statement, parameters, context=context) File "/usr/lib/python2.4/site-packages/sqlalchemy/engine/base.py", line 351, in _execute raise exceptions.SQLError(statement, parameters, e) SQLError: (OperationalError) no such table: system 'INSERT INTO system (port, base_url, host, name) VALUES (?, ?, ?, ?)' [80, '/', 'www.debian.org', 'lala'] ---------------------------------------------------------------------- Ran 2 tests in 1.518s FAILED (errors=1) =================================================================== Any ideas? Thanks, -- Gustavo Noronha Silva <[EMAIL PROTECTED]> http://people.debian.org/~kov/ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

