Google Groups Home
Help | Sign in
Problem/questions with testing Model
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  8 messages - Collapse all
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
Denny  
View profile
 More options Apr 16 2007, 3:13 pm
From: "Denny" <dth...@comcast.net>
Date: Mon, 16 Apr 2007 12:13:19 -0700
Local: Mon, Apr 16 2007 3:13 pm
Subject: Problem/questions with testing Model
I am a newbie to TurboGears and to Python.  Been studying TurboGears
for a couple of weeks, and when trying to implement testing, I'm
having some problems/questions!

1.  I've modified the sample test scripts (in the '/tests' directory),
then run nosetests.  I kept getting the error:
        ProgrammingError: (1146, "Table 'research_test.sandboxes'
doesn't exist")

I'm using MySQL on  Ubuntu Linux.  I have defined different databases
for development and testing (research and research_test respectively.

 I finally manually created the sandboxes table.  Re-running nosetests
reported other errors in my code which I was able to correct.  I ran
nosetests again, and the sandboxes table was again missing!!

My model defines a single table with 8 fields.  'tg-admin sql create'
successfully creates this table in the development database, but I
can't find a way to create the table in the testing database!!?!

Is there a way to have the model table(s) created (either
programmaticaly or some tg-admin command) AND/OR prevent the testing
tables from being deleted when running nosetests??

Thanks in advance,
   Denny


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Joost Moesker  
View profile
 More options Apr 16 2007, 6:13 pm
From: "Joost Moesker" <JoostMoes...@gmail.com>
Date: Mon, 16 Apr 2007 15:13:04 -0700
Local: Mon, Apr 16 2007 6:13 pm
Subject: Re: Problem/questions with testing Model
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.

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Marco Mariani  
View profile
 More options Apr 17 2007, 8:35 am
From: Marco Mariani <marco.mari...@prometeia.it>
Date: Tue, 17 Apr 2007 14:35:44 +0200
Local: Tues, Apr 17 2007 8:35 am
Subject: Re: [TurboGears] Re: Problem/questions with testing Model

Joost Moesker wrote:
> The setup and tearDown methods on testutils.DBTest automatically
> create and drop the database schema per testcase.

DBTest is SQLObject-specific

In my case (with sqlalchemy) I cannot drop and recreate the schema for
each test because it would take too much time -- the schema is
postgres-specific, autoloaded, and has triggers, bells and whistles.

I've come up with this:

Works for me.
The first session.clear() is suspicious, but I had no time to
investigate yet

    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Denny  
View profile
 More options Apr 17 2007, 5:57 pm
From: Denny <dth...@comcast.net>
Date: Tue, 17 Apr 2007 14:57:51 -0700
Local: Tues, Apr 17 2007 5:57 pm
Subject: Re: Problem/questions with testing Model
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:researcher@localhost:
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" <JoostMoes...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ian Wilson  
View profile
 More options Apr 17 2007, 10:35 pm
From: "Ian Wilson" <vengfulsquir...@gmail.com>
Date: Tue, 17 Apr 2007 19:35:56 -0700
Local: Tues, Apr 17 2007 10:35 pm
Subject: Re: [TurboGears] Re: Problem/questions with testing Model
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:researcher@local host:
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 <dth...@comcast.net> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Denny  
View profile
 More options Apr 18 2007, 12:28 pm
From: Denny <dth...@comcast.net>
Date: Wed, 18 Apr 2007 09:28:46 -0700
Local: Wed, Apr 18 2007 12:28 pm
Subject: Re: Problem/questions with testing Model
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" <vengfulsquir...@gmail.com> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Ian Wilson  
View profile
 More options Apr 18 2007, 4:07 pm
From: "Ian Wilson" <vengfulsquir...@gmail.com>
Date: Wed, 18 Apr 2007 13:07:14 -0700
Local: Wed, Apr 18 2007 4:07 pm
Subject: Re: [TurboGears] Re: Problem/questions with testing Model
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 <dth...@comcast.net> wrote:


    Reply to author    Forward  
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Denny  
View profile
 More options Apr 19 2007, 7:12 pm
From: Denny <dth...@comcast.net>
Date: Thu, 19 Apr 2007 16:12:30 -0700
Local: Thurs, Apr 19 2007 7:12 pm
Subject: Re: Problem/questions with testing Model
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" <vengfulsquir...@gmail.com> wrote: