Web2py 谷歌应用程序引擎测试

发布于 2024-12-11 02:10:23 字数 2833 浏览 0 评论 0原文

我正在使用 web2py 构建 GAE 应用程序,并且正在努力设置测试框架。 我研究过:

  • web2py_utils
  • nosegae
  • Google 员工 Ikai Lan 的 建议
  • 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))

< strong>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 应用程序设置测试框架?之一

I'm building an GAE app with web2py and am struggling with setting up a test framework.
I've looked into:

Here's a unit test I attempted:

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,)

I get the following error when execute my run_fb_tests.py

ImportError: No module named google.appengine.ext

I've been banging my head for days now with many errors. This is only one of many

How do you setup a testing framework in web2py for GAE apps?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

你的往事 2024-12-18 02:10:23

你的脚本 run_fb_tests.py 在哪里?如果它位于 web2py 文件夹中,我会收到类似的错误,但如果您将其放在 google_appenine 中,或放在 google_appengine 的包含文件夹中,则我不会收到导入错误。

Where is your script run_fb_tests.py? If it is in the web2py folder I get a similar error, but if you place it in google_appenine, or in the containing folder of the google_appengine then I get no import errors.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文