I'm using the blobstore with my Google App Engine app, and everything is working fine on the production server and the development server. Testing with testbed and webtest, however, isn't working...
In my tests, the blob exists as I can access it like this:
blob = self.blobstore_stub.storage._blobs[key]
When I try to download a blob in my tests like this
response = self.app.get("/blob-download/2")
my blobstore download handler never gets called and I get a 404 error (but the link works on the dev or prod servers).
I suspect this is an error with testbed or webtest...
Any ideas as to what I might be doing wrong, or if this is an error with testbed/webtest what a good work around might be so that I can test this part of my code?
Here is some info about how I am setting up my tests.
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
This is the relevant portion of app.yaml:
handlers:
- url: /.*
script: main.application
This is the relevant portion of main.py:
application = webapp2.WSGIApplication(
[
('/blob-download/([^/]+)?', views.BlobDownload),
]