我想对来自Google App Engine webapp.WSGIApplication的响应进行单元测试,例如请求url'/'并测试响应状态代码为200,使用 GAEUnit。我怎样才能做到这一点?
我想使用webapp框架和GAEUnit,它在App Engine沙箱中运行(不幸的是 WebTest的 在沙箱内不起作用)。
我想对来自Google App Engine webapp.WSGIApplication的响应进行单元测试,例如请求url'/'并测试响应状态代码为200,使用 GAEUnit。我怎样才能做到这一点?
我想使用webapp框架和GAEUnit,它在App Engine沙箱中运行(不幸的是 WebTest的 在沙箱内不起作用)。
我添加了一个 样品申请 到GAEUnit项目,该项目演示了如何使用GAEUnit编写和执行Web测试。该示例包含一个稍微修改过的版本'WebTest的按照David Coffin的建议,'module('import webbrowser'被注释掉了)。
这是示例应用程序'test'目录中的'web_tests.py'文件:
import unittest
from webtest import TestApp
from google.appengine.ext import webapp
import index
class IndexTest(unittest.TestCase):
def setUp(self):
self.application = webapp.WSGIApplication([('/', index.IndexHandler)], debug=True)
def test_default_page(self):
app = TestApp(self.application)
response = app.get('/')
self.assertEqual('200 OK', response.status)
self.assertTrue('Hello, World!' in response)
def test_page_with_param(self):
app = TestApp(self.application)
response = app.get('/?name=Bob')
self.assertEqual('200 OK', response.status)
self.assertTrue('Hello, Bob!' in response)
我添加了一个 样品申请 到GAEUnit项目,该项目演示了如何使用GAEUnit编写和执行Web测试。该示例包含一个稍微修改过的版本'WebTest的按照David Coffin的建议,'module('import webbrowser'被注释掉了)。
这是示例应用程序'test'目录中的'web_tests.py'文件:
import unittest
from webtest import TestApp
from google.appengine.ext import webapp
import index
class IndexTest(unittest.TestCase):
def setUp(self):
self.application = webapp.WSGIApplication([('/', index.IndexHandler)], debug=True)
def test_default_page(self):
app = TestApp(self.application)
response = app.get('/')
self.assertEqual('200 OK', response.status)
self.assertTrue('Hello, World!' in response)
def test_page_with_param(self):
app = TestApp(self.application)
response = app.get('/?name=Bob')
self.assertEqual('200 OK', response.status)
self.assertTrue('Hello, Bob!' in response)
实际上,只要你注释掉,WebTest就可以在沙盒中工作
import webbrowser
在webtest / __ init__.py中