【发布时间】:2011-10-21 23:31:25
【问题描述】:
我正在使用 web2py 构建一个 GAE 应用程序,并且正在努力建立一个测试框架。 我调查过:
- web2py_utils
- 鼻子
- Google 员工 Ikai Lan 的 suggestions
- gaetestbed 已合并到 GAE apis
这是我尝试的单元测试:
import unittest
import nose
from nose.tools import *
from google.appengine.ext import testbed
from google.appengine.datastore import datastore_stub_itil
class UserModelTest(unittest.TestCase):
def setUp(self):
# First, create an instance of the Testbed class.
self.testbed = testbed.Testbed()
# Then activate the testbed, which prepares the service stubs for use.
self.testbed.activate()
# Initialize the datastore stub with this policy.
self.testbed.init_datastore_v3_stub(consistency_policy=self.policy)
self.env = new_env(app='fb', controller='default')
self.db = copy_db(self.env, db_name='db', db_link='sqlite:memory')
self.user = self.db.auth_user.insert(first_name='Bob', last_name='Narley', fb_id=1, password='testtest')
self.dream = self.db.dream.insert(title='Graduate UC Santa Cruz with Computer Science degree by June 8, 2012.',
type='education', owner = self.user, progress=92.0)
self.task1 = self.db.task.insert(dream=self.dream, title='Buy batteries for calculator', solution='Go to Walmart at 12:00pm October 30, 2012 and buy Duracell AAA.',
status=1)
self.task2 = self.db.task.insert(dream=self.dream, title='Make Winston happy',
solution='Make banana milk',
status=0)
self.user.update_record(tasks=[self.task1, self.task2])
def tearDown(self):
self.testbed.deactivate()
def test_create_user(self):
assert_equal('Bob', self.user.first_name)
assert_equal(1, self.user.fb_id)
assert_equal('testtest', self.user.password)
def test_user_has_many_tasks(self):
tasks = self.db(self.db.task.id.belongs(self.user.tasks)).select()
assert_equal(2, len(tasks))
run_fb_tests.py:
from web2py_utils.test_runner import run
import sys
run(path = sys.path[0],
app = 'fb',
test_key = 'superSecret',
test_options = {'verbosity': 3, 'with-gae': True, 'without-sandbox': True},
coverage_report = 'logs/coverage_report.txt',
DO_COVER = True,
DO_NOSE = True,)
执行 run_fb_tests.py 时出现以下错误
ImportError:没有名为 google.appengine.ext 的模块
我这几天一直在敲我的脑袋,犯了很多错误。这只是众多之一
如何在 web2py 中为 GAE 应用设置测试框架?
【问题讨论】:
-
+1 我很感兴趣,因为我选择 web2py 进行一次部署 joeyonlinecorner.appspot.com 现在我们想添加类似 wiki 或博客的东西,但我无法获得任何 web2py 插件与 GAE 一起工作,即使 web2py 作者特别说测试了至少一个使用 GAE 的插件。如果您发布到 google web2py 组,作者可能会阅读您的问题和答案。
-
在调用
run()之前输入print sys.path会看到什么? google.appengine 在这条路上吗?代码中似乎没有任何内容专门排除它,所以我想知道脚本是否只是不知道您的 App Engine 包在哪里。