2
我正在用web2py構建GAE應用程序,並且正在努力設置測試框架。 我已經研究過:Web2py Google App Engine測試
- web2py_utils
- nosegae
- Google用戶Ikai嵐的suggestions
- gaetestbed這是合併到GAE的API
這裏有一個單元測試我企圖:
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
導入錯誤:沒有模塊名爲google.appengine.ext
現在我有很多錯誤讓我的頭腦震動了好幾天。這只是其中的一個
+1我會感興趣,因爲我選擇了web2py一個部署http://joeyonlinecorner.appspot.com,現在我們想要添加類似維基或博客的東西,但我無法獲得任何web2py插件與GAE一起工作,即使web2py作者spicifically說測試過的至少一個插件GAE。如果您發佈到谷歌web2py組,作者可能會閱讀您的問題和答案。 –
當你在調用'run()'之前放置'print sys.path'時,你會看到什麼? google.appengine是否在該路徑上?在代碼中似乎沒有明確排除它的任何內容,所以我想知道腳本是否僅僅不知道App Engine包的位置。 –