Thank you, howesc. I'll take a close look at your file.

I finally cobbled together a file to unit test an object in my project
that uses the unittest library, Google's memcache and the testbed
library, and a web2py model. I am hoping it will scale up to test
controller actions as well as individual modules.

Included below is the relevant portion of that file. Notice the part
where I had to manually add a path to dev_appserver's yaml library. I
had to do that to import the testbed module.

Here is the command line to run my unit test.

$ cd web2py
$ python web2py.py -S myproj -M -R applications/myproj/test/
test_account.py

------

import sys, unittest

from google.appengine.api import memcache

yaml_path = '~/google_appengine_1.6.3_source/google_appengine/lib/yaml/
lib/'
sys.path.append (yaml_path)

from google.appengine.ext import testbed

from account_list import Account_List
from account import Account
class Test_Account_List (unittest.TestCase):
        def setUp (self):
                self.testbed = testbed.Testbed()
                self.testbed.activate()
                self.testbed.init_memcache_stub()

        def test_account_list (self):
                al1 = Account_List (db)
                al1.clear_list (db)    # To start from a known state
                al2 = Account_List (db)
                self.assertIs (al1, al2)
                active_list1 = memcache.get ('account_list')
                active_list2 = al2.active_accounts(db)
                self.assertEqual (active_list1, active_list2)

        def tearDown (self):
                self.testbed.deactivate()


suite = unittest.TestSuite()
suite.addTest (unittest.makeSuite (Test_Account))
suite.addTest (unittest.makeSuite (Test_Account_List))
unittest.TextTestRunner (verbosity = 2).run (suite)


On Mar 21, 2:35 am, howesc <how...@umich.edu> wrote:
> attached is a controller that i use, adapted from the testing tools in the
> admin interface.  note that i set a request parameter 'test_db' and in
> models i detect that parameter and connect to a different namespace so that
> my tests run in a controlled DB environment - remember that if you want to
> setup some test data to start with. :)
>
> i have not used this in a live GAE environment so i don't know how well it
> works.  i fear that extensive tests would run past the 60 second timeout
> for web requests.
>
> let me know if you have questions.
>
>
>
>
>
>
>
> On Tuesday, March 20, 2012 1:54:03 PM UTC-7, David Phillips wrote:
>
> > I am writing a web application using web2py for execution on app
> > engine. I've deployed other web2py apps there but I've never used any
> > app engine-specific utilities. In this project I want to use app
> > engine's taskqueue and run it on a backend instance.
>
> > I'm developing on app engine's dev_appserver which is working out
> > okay, but but I'm not seeing how to do unit testing.
>
> > Is this a problem that has been solved already?
>
>
>
>  tests.py
> 6KViewDownload

Reply via email to