Web2py Google App Engine测试

时间:2011-10-21 23:31:26

标签: google-app-engine web2py

我正在使用web2py构建一个GAE应用程序,并且正在努力设置测试框架。 我调查了一下:

这是我尝试的单元测试:

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 个答案:

答案 0 :(得分:0)

你的脚本run_fb_tests.py在哪里?如果它在web2py文件夹中,我会收到类似的错误,但是如果你将它放在google_appenine中,或者放在google_appengine的包含文件夹中,那么我没有导入错误。