Unittests для сервера на Flask
Пишу юниттест для функции flask-сервера, которая, в зависимости от присланных данных, возвращает разные http ответы. Проблема в том, что на коды ответов 400+ прилетает ошибка "werkzeug.exceptions.BadRequest: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand"
class TestChecker(unittest.TestCase):
def setUp(self):
app.config['TESTING'] = True
app.config['CSRF_ENABLED'] = False
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///' + os.path.join(basedir, 'test.db')
self.app = app.test_client()
database.create_all()
def tearDown(self):
database.session.remove()
database.drop_all()
def test_checking_file(self):
with open('1.jpg', 'rb') as sent_file:
correct_file = FileStorage(sent_file)
correct_result = checking_file(correct_file)
self.assertEqual(correct_result, 202) # тут работает
with open('error.jpg', 'rb') as error_format:
error_format_file = FileStorage(error_format)
result = checking_file(error_format_file) # на этой строчке вылетает ошибка
self.assertEqual(result, 422) # интерпретатор не доходит сюда, менял запрос на любой из 400```
Есть идеи? Спасибо!