我爲我的Flask集成測試使用Flask-Testing。我有一個文件上傳的文件,我試圖編寫測試,但我不斷收到一個錯誤:TypeError: 'str' does not support the buffer interface
。在Flask中測試文件上傳
我正在使用Python 3.我找到的最接近的答案是this,但它不適用於我。
這是我的許多嘗試之一是這樣的:
def test_edit_logo(self):
"""Test can upload logo."""
data = {'name': 'this is a name', 'age': 12}
data['file'] = (io.BytesIO(b"abcdef"), 'test.jpg')
self.login()
response = self.client.post(
url_for('items.save'), data=data, follow_redirects=True)
})
self.assertIn(b'Your item has been saved.', response.data)
advert = Advert.query.get(1)
self.assertIsNotNone(item.logo)
怎樣一個測試在燒瓶內的文件上傳?
我非常愛你,現在我會吻你。我花了整整一小時試圖弄清楚什麼是錯誤的......好的先生,你是我的救世主。 – Rodrigo