how to simulate image upload to google app engine blobstore

[亡魂溺海] 提交于 2019-12-06 09:17:23

问题


I'm uploading images to the GAE blobstore using create_upload_url

uploadURL = blobstore.create_upload_url('/upload')

For the purpose of unit testing the gae code, can you simulate the image upload? OR should I insert the image data in my test bed and assume the upload is successful? If so, how do you upload an image to the test bed?


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/10928339/how-to-simulate-image-upload-to-google-app-engine-blobstore

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