Exception on JSONResponse
AlexanderDavid opened this issue · comments
When trying to perform a POST request to a JSON endpoint I get the following error:
FAILED tests/test_extraction.py::test_extract_get_response - TypeError: '<class 'pytest_flask.plugin.JSONResponse'>' object is not iterable
The long error is as follows:
client = <FlaskClient <Flask 'extraction_app'>>
def test_extract_get_response(client):
> assert client.post("/extract").status_code == 400
tests/test_extraction.py:16:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
../.local/share/virtualenvs/extraction_webserver-xxVKyGze/lib/python3.8/site-packages/werkzeug/test.py:1016: in post
return self.open(*args, **kw)
../.local/share/virtualenvs/extraction_webserver-xxVKyGze/lib/python3.8/site-packages/flask/testing.py:222: in open
return Client.open(
../.local/share/virtualenvs/extraction_webserver-xxVKyGze/lib/python3.8/site-packages/werkzeug/test.py:970: in open
response = self.run_wsgi_app(environ.copy(), buffered=buffered)
../.local/share/virtualenvs/extraction_webserver-xxVKyGze/lib/python3.8/site-packages/werkzeug/test.py:861: in run_wsgi_app
rv = run_wsgi_app(self.application, environ, buffered=buffered)
../.local/share/virtualenvs/extraction_webserver-xxVKyGze/lib/python3.8/site-packages/werkzeug/test.py:1114: in run_wsgi_app
for item in app_iter:
../.local/share/virtualenvs/extraction_webserver-xxVKyGze/lib/python3.8/site-packages/werkzeug/wsgi.py:506: in __next__
return self._next()
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
iterable = <<class 'pytest_flask.plugin.JSONResponse'> 81 bytes [200 OK]>, charset = 'utf-8'
def _iter_encoded(iterable, charset):
> for item in iterable:
E TypeError: '<class 'pytest_flask.plugin.JSONResponse'>' object is not iterable
This was because I was not returning the JSON object correctly. Fixed in the main flask code and now tests run.