The problem ended up when adding content_type='multipart/form-data' to the post method, all values ββin data will either be files or strings. My dict data had integers that I realized thanks to this comment.
So, the final solution was as follows:
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)
source share