我目前正在使用python_flickr_api为我的应用上传照片:它用于httplib
执行多部分 POST 请求。
问题:我想通过拦截 POST 请求并创建预先设置的成功响应来验证上传确实是在集成测试中发出的,以便我的测试可以完全离线运行而不依赖于 Flickr(我不想上传相同的测试图像 100 次,要么!)
为此,我尝试使用两个令人难以置信的库:VCRPy和HTTPretty。它们都没有解决我的问题,因为它们都不支持httplib
(HTTPretty 最接近,httplib2
仅支持),并且我收到一个看起来像这样的错误:
Failure/Error: [Errno 32] Broken pipe
Traceback:
...
File "/usr/local/lib/python2.7/site-packages/flickr_api/upload.py", line 92, in upload
r = post(UPLOAD_URL,auth.AUTH_HANDLER,args,photo_file)
File "/usr/local/lib/python2.7/site-packages/flickr_api/upload.py", line 52, in post
r = multipart.posturl(url,fields,files)
File "/usr/local/lib/python2.7/site-packages/flickr_api/multipart.py", line 19, in posturl
return post_multipart(urlparts[1], urlparts[2], fields,files)
File "/usr/local/lib/python2.7/site-packages/flickr_api/multipart.py", line 33, in post_multipart
h.send(body)
File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 805, in send
self.sock.sendall(data)
File "/usr/local/lib/python2.7/site-packages/httpretty/core.py", line 243, in sendall
return self._true_sendall(data)
File "/usr/local/lib/python2.7/site-packages/httpretty/core.py", line 216, in _true_sendall
self.truesock.sendall(data, *args, **kw)
File "/usr/local/Cellar/python/2.7.5/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 224, in meth
return getattr(self._sock,name)(*args)
很明显httpretty
正在拦截,但正在导致管道破裂。
我怎样才能解决这个问题?