The issue ended up not being that when one adds content_type='multipart/form-data'
to the post
method it expect all values in data
to either be files or strings. There were integers in my data dict which I realised thanks to this comment.
So the end solution ended up looking like this:
def test_edit_logo(self):
"""Test can upload logo."""
data = {'name': 'this is a name', 'age': 12}
data = {key: str(value) for key, value in data.items()}
data['file'] = (io.BytesIO(b"abcdef"), 'test.jpg')
self.login()
response = self.client.post(
url_for('adverts.save'), data=data, follow_redirects=True,
content_type='multipart/form-data'
)
self.assertIn(b'Your item has been saved.', response.data)
advert = Item.query.get(1)
self.assertIsNotNone(item.logo)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…