how to simulate image upload to google app engine blobstore

旧城冷巷雨未停 提交于 2019-12-04 17:03:37

Agree with @fredrik on what exactly you're testing there.

Anyway, if you're doing some functional/blackbox/similar testing, you could simply use Webtest framework (see post method) and do the actual upload, e.g.

payload = [(fieldname, filename)]
test_app.post(uploadURL, upload_files=payload)

Have a look at Handler Testing for Python for details on how to initialize the above test_app.

Could you provided some code on how your test look?

I think you should be able to fake a request to the upload_url using webapp2. Have a look here for some sample code on how to fake requests.

On the other hand you should think of what the purpose of your test is. Is the purpose to test that the image upload works or is it how your code works after the upload is complete?

When running unit-tests try to break the dependencies to other libraries so that you only test you own code. And then add a new suite of implementation test, ie make a request for and url and check that you get the expected response. As in test_redirect_if_no_session of the example above, make a request to a page that requires a user and expect a redirect (http response code 302).

..fredrik

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!