【发布时间】:2014-12-09 09:53:54
【问题描述】:
我有一个小型烧瓶应用程序,它需要一些图像进行上传并将它们转换为多页 tiff。没什么特别的。
但是如何测试多个文件的上传和文件下载呢?
我的测试客户:
class RestTestCase(unittest.TestCase):
def setUp(self):
self.dir = os.path.dirname(__file__)
rest = imp.load_source('rest', self.dir + '/../rest.py')
rest.app.config['TESTING'] = True
self.app = rest.app.test_client()
def runTest(self):
with open(self.dir + '/img/img1.jpg', 'rb') as img1:
img1StringIO = StringIO(img1.read())
response = self.app.post('/convert',
content_type='multipart/form-data',
data={'photo': (img1StringIO, 'img1.jpg')},
follow_redirects=True)
assert True
if __name__ == "__main__":
unittest.main()
应用程序将文件发回
return send_file(result, mimetype='image/tiff', \
as_attachment=True)
我想读取响应中发送的文件并将其与另一个文件进行比较。如何从响应对象中获取文件?
【问题讨论】:
-
rest.py 的内容是什么(或者它来自什么包),更具体地说,app.post 是什么样的?
-
rest.py 是我的烧瓶应用程序。 convert 方法,我在其中发布一些图像转换,并以调用 flask.send_file 结束。 app.post 是来自 flask.test_client 的方法。