我将 blobstore 与我的 Google App Engine 应用程序一起使用,并且在生产服务器和开发服务器上一切正常。使用测试台进行测试和webtest http://webtest.pythonpaste.org/但是,不起作用...
在我的测试中,该 blob 存在,因为我可以像这样访问它:
blob = self.blobstore_stub.storage._blobs[key]
当我尝试像这样在测试中下载 blob 时
response = self.app.get("/blob-download/2")
我的 blobstore 下载处理程序从未被调用,并且收到 404 错误(但该链接在开发或生产服务器上有效)。
我怀疑这是 testbed 或 webtest 的错误......
关于我可能做错了什么,或者如果这是 testbed/webtest 的错误,有什么想法可以做,以便我可以测试这部分代码?
以下是有关我如何设置测试的一些信息。
import unittest
from webtest import TestApp
from google.appengine.ext import db, testbed
from google.appengine.api import users
from google.appengine.api import apiproxy_stub_map
class ExampleTests(unittest.TestCase):
def setUp(self):
self.testbed = testbed.Testbed()
self.testbed.setup_env(app_id="stv")
self.testbed.activate()
self.testbed.init_datastore_v3_stub()
self.testbed.init_taskqueue_stub()
self.testbed.init_mail_stub()
self.testbed.init_blobstore_stub()
self.app = TestApp(main.application)
apiproxy_stub_map.apiproxy.GetStub("datastore_v3").Clear()
self.taskqueue_stub = apiproxy_stub_map.apiproxy.GetStub('taskqueue')
self.mail_stub = apiproxy_stub_map.apiproxy.GetStub('mail')
self.blobstore_stub = apiproxy_stub_map.apiproxy.GetStub('blobstore')
def testBlob(self):
# create blob using files.blobstore.create
response = self.app.get("/blob-download/2") # This returns 404
self.assertEqual(response.body, "content of blob") # This fails
这是 app.yaml 的相关部分:
handlers:
- url: /.*
script: main.application
这是 main.py 的相关部分:
application = webapp2.WSGIApplication(
[
('/blob-download/([^/]+)?', views.BlobDownload),
]