I tried what you suggested, and commented out the import of my
controllers!
The 1st think that failed was initializing cherrypy.root
I commented THAT out, and now the line:
result = turbogears.testutil.call(cherrypy.root.index)
fails, because cherrypy,root is not initialized!!!
It looks like, in order to test, my 'index' controller, I need to
import my controllers!
Now what do I do??
thanks,
Denny
On Apr 18, 2:07 pm, "Ian Wilson" <[EMAIL PROTECTED]> wrote:
> Ummm it doesn't look like you even use controllers. So why don't you
> try it without that import.
>
> -Ian
>
> On 4/18/07, Denny <[EMAIL PROTECTED]> wrote:
>
>
>
> > Still no-go!!! 'nosetests' seems to fail while importing my
> > 'research.controllers' module. It seems to want the database tables
> > during that import. The below traceback is pointing to a function in
> > my controllers.py which makes queries for data to be presented in a
> > radio button list. Am I doing something fundamentally wrong??
>
> > Here's the recent traceback!
>
> > > nosetests
> > E.
> > ======================================================================
> > ERROR: test module research.tests.test_controllers in /home/dthury/
> > projects/Somerville/research
> > ----------------------------------------------------------------------
> > Traceback (most recent call last):
> > File "/usr/lib/python2.4/site-packages/nose-0.9.2-py2.4.egg/nose/
> > suite.py", line 51, in run
> > self.setUp()
> > File "/usr/lib/python2.4/site-packages/nose-0.9.2-py2.4.egg/nose/
> > suite.py", line 200, in setUp
> > self.module = _import(self.moduleName, [self.path], self.conf)
> > File "/usr/lib/python2.4/site-packages/nose-0.9.2-py2.4.egg/nose/
> > importer.py", line 101, in _import
> > mod = load_module(fqname, fh, filename, desc)
>
> > <--- below is from my code --->
>
> > File "/home/dthury/projects/Somerville/research/research/tests/
> > test_controllers.py", line 8, in ?
> > from research.controllers import *
> > File "/home/dthury/projects/Somerville/research/research/
> > controllers.py", line 27, in ?
> > class sandboxSelectionFields(widgets.WidgetsList):
> > File "/home/dthury/projects/Somerville/research/research/
> > controllers.py", line 28, in sandboxSelectionFields
> > sandboxID = widgets.RadioButtonList(options=get_sandbox_options(),
> > validator=validators.NotEmpty)
> > File "/home/dthury/projects/Somerville/research/research/
> > controllers.py", line 22, in get_sandbox_options
> > for sandbox in sandbox_list:
>
> > <--- The above line is referring to a line of code where I'm
> > iterating over the results of a db query
> > But this is done before the setUp function is run to create/
> > load my test database!! --->
>
> > File "/usr/lib/python2.4/site-packages/SQLObject-0.7.4-py2.4.egg/
> > sqlobject/sresults.py", line 155, in __iter__
> > return iter(list(self.lazyIter()))
> > File "/usr/lib/python2.4/site-packages/SQLObject-0.7.4-py2.4.egg/
> > sqlobject/sresults.py", line 163, in lazyIter
> > return conn.iterSelect(self)
> > File "/usr/lib/python2.4/site-packages/SQLObject-0.7.4-py2.4.egg/
> > sqlobject/dbconnection.py", line 365, in iterSelect
> > select, keepConnection=False)
> > File "/usr/lib/python2.4/site-packages/SQLObject-0.7.4-py2.4.egg/
> > sqlobject/dbconnection.py", line 705, in __init__
> > self.dbconn._executeRetry(self.rawconn, self.cursor, self.query)
> > File "/usr/lib/python2.4/site-packages/SQLObject-0.7.4-py2.4.egg/
> > sqlobject/mysql/mysqlconnection.py", line 78, in _executeRetry
> > return cursor.execute(myquery)
> > File "/usr/lib/python2.4/site-packages/MySQLdb/cursors.py", line
> > 137, in execute
> > self.errorhandler(self, exc, value)
> > File "/usr/lib/python2.4/site-packages/MySQLdb/connections.py", line
> > 33, in defaulterrorhandler
> > raise errorclass, errorvalue
> > ProgrammingError: (1146, "Table 'research_test.sandboxes' doesn't
> > exist")
>
> > ----------------------------------------------------------------------
> > Ran 1 test in 1.516s
>
> > FAILED (errors=1)
>
> > #--------------------------------------------------------------------------------
>
> > On Apr 17, 8:35 pm, "Ian Wilson" <[EMAIL PROTECTED]> wrote:
> > > The following setup will DROP and CREATE your database therefore
> > > deleting all data in it before each test. You will need to populate
> > > your data base with test data in the setUp method.
>
> > > import turbogears.testutil
> > > import turbogears.database
> > > import sqlobject
>
> > > turbogears.database.set_db_uri("notrans_mysql://researcher:[EMAIL
> > > PROTECTED]:
> > > 3306/research_test")
>
> > > import research.model
> > > from research.controllers import *
> > > from research.model import *
> > > import cherrypy
>
> > > cherrypy.root = Root()
>
> > > class TestModel(turbogears.testutil.DBTest):
>
> > > model = research.model
>
> > > def setUp(self):
> > > turbogears.testutil.DBTest.setUp(self)
> > > #SETUP TEST DATA HERE
>
> > > def test_sandbox_controller():
> > > result = testutil.call(cherrypy.root.play)
> > > print 'play returned :', result
> > > assert result == True
>
> > > ....
>
> > > On 4/17/07, Denny <[EMAIL PROTECTED]> wrote:
>
> > > > I don't understand what you're saying here!!??!! Can you be more
> > > > specific about what needs to be done,
> > > > may examples of what I may need to add to my testing code!?!! I'm not
> > > > using SQLite, but MySQL.
>
> > > > My test.cfg contains:
>
> > > > sqlobject.dburi="notrans_mysql://researcher:[EMAIL PROTECTED]:
> > > > 3306/research_test"
>
> > > > test-models.py seems to complete OK. but test-controllers.py is where
> > > > my problem seems to be.
> > > > If I manually create the required table in the above database,
> > > > nosetests completes successfully, but
> > > > the table has been deleted!!?!!
>
> > > > Below are the results of my latest nosetests run; and
> > > > the contents of my test-controllers.py (which seems to be what's
> > > > failing):
>
> > > > ======================================================================
> > > > ERROR: test module research.tests.test_controllers in /home/dthury/
> > > > projects/Somerville/research
> > > > ----------------------------------------------------------------------
> > > > Traceback (most recent call last):
> > > > File "/usr/lib/python2.4/site-packages/nose-0.9.2-py2.4.egg/nose/
> > > > suite.py", line 51, in run
> > > > self.setUp()
> > > > File "/usr/lib/python2.4/site-packages/nose-0.9.2-py2.4.egg/nose/
> > > > suite.py", line 200, in setUp
> > > > self.module = _import(self.moduleName, [self.path], self.conf)
> > > > File "/usr/lib/python2.4/site-packages/nose-0.9.2-py2.4.egg/nose/
> > > > importer.py", line 101, in _import
> > > > mod = load_module(fqname, fh, filename, desc)
> > > > File "/home/dthury/projects/Somerville/research/research/tests/
> > > > test_controllers.py", line 2, in ?
> > > > from research.controllers import *
> > > > File "/home/dthury/projects/Somerville/research/research/
> > > > controllers.py", line 26, in ?
> > > > class sandboxSelectionFields(widgets.WidgetsList):
> > > > File "/home/dthury/projects/Somerville/research/research/
> > > > controllers.py", line 27, in sandboxSelectionFields
> > > > sandboxID = widgets.RadioButtonList(options=get_sandbox_options(),
> > > > validator=validators.NotEmpty)
> > > > File "/home/dthury/projects/Somerville/research/research/
> > > > controllers.py", line 21, in get_sandbox_options
> > > > for sandbox in sandbox_list:
> > > > File "/usr/lib/python2.4/site-packages/SQLObject-0.7.4-py2.4.egg/
> > > > sqlobject/sresults.py", line 155, in __iter__
> > > > return iter(list(self.lazyIter()))
> > > > File "/usr/lib/python2.4/site-packages/SQLObject-0.7.4-py2.4.egg/
> > > > sqlobject/sresults.py", line 163, in lazyIter
> > > > return conn.iterSelect(self)
> > > > File "/usr/lib/python2.4/site-packages/SQLObject-0.7.4-py2.4.egg/
> > > > sqlobject/dbconnection.py", line 365, in iterSelect
> > > > select, keepConnection=False)
> > > > File "/usr/lib/python2.4/site-packages/SQLObject-0.7.4-py2.4.egg/
> > > > sqlobject/dbconnection.py", line 705, in __init__
> > > > self.dbconn._executeRetry(self.rawconn, self.cursor, self.query)
> > > > File "/usr/lib/python2.4/site-packages/SQLObject-0.7.4-py2.4.egg/
> > > > sqlobject/mysql/mysqlconnection.py", line 78, in _executeRetry
> > > > return cursor.execute(myquery)
> > > > File "/usr/lib/python2.4/site-packages/MySQLdb/cursors.py", line
> > > > 137, in execute
> > > > self.errorhandler(self, exc, value)
> > > > File "/usr/lib/python2.4/site-packages/MySQLdb/connections.py", line
> > > > 33, in defaulterrorhandler
> > > > raise errorclass, errorvalue
> > > > ProgrammingError: (1146, "Table 'research_test.sandboxes' doesn't
> > > > exist")
>
> > > > ----------------------------------------------------------------------
> > > > Ran 1 test in 1.636s
>
> > > > FAILED (errors=1)
>
> > > > ==================================================
> > > > ===================test controllers.py====================
>
> > > > from turbogears import testutil
> > > > from research.controllers import *
> > > > from research.model import *
> > > > import cherrypy
>
> > > > cherrypy.root = Root()
>
> > > > def test_sandbox_controller():
> > > > result = testutil.call(cherrypy.root.play)
> > > > print 'play returned :', result
> > > > assert result == True
>
> > > > def test_method():
> > > > "the index method should return a string called now"
> > > > import types
> > > > result = testutil.call(cherrypy.root.index)
> > > > print "Index method returned:", result
>
> > > > def test_indextitle():
> > > > "The indexpage should have the right title"
> > > > testutil.createRequest("/")
> > > > print cherrypy.response.body[0]
> > > > assert "<title>SNP Research System</title>" in
> > > > cherrypy.response.body[0]
>
> > > > Thanks,
> > > > Denny
>
> > > > On Apr 16, 4:13 pm, "Joost Moesker" <[EMAIL PROTECTED]> wrote:
> > > > > The setup and tearDown methods on testutils.DBTest automatically
> > > > > create and drop the database schema per testcase. For this to work
> > > > > you need to set the model attribute of the class to reference your
> > > > > model module. It's common to use an SQLite 'in memory' database for
> > > > > unittests to speed-up the peformance.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---