Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flask test_client can't handle HTTP 204 No data

I have delete endpoint, returning HTTP 204

@blueprint.route('/foo', methods=['DELETE'])
def delete_tag(id):
    # ....
    return '', 204

and I want to test it

def test_delete_tag(self):
    resp = self.client.delete(url_for('tags.delete_tag', id=1))
    self.assertEqual(resp.status_code, 204)

but I got exception

Traceback (most recent call last):
  File "tests/tags_test.py", line 31, in test_delete_tag
    resp = self.client.delete(url_for('tags.delete_tag', id=1)})
  File ".virtualenvs/...site-packages/werkzeug/test.py", line 799, in delete
    return self.open(*args, **kw)
  File ".virtualenvs/...site-packages/flask/testing.py", line 108, in open
    follow_redirects=follow_redirects)
  File ".virtualenvs/...site-packages/werkzeug/test.py", line 742, in open
    response = self.run_wsgi_app(environ, buffered=buffered)
  File ".virtualenvs/...site-packages/werkzeug/test.py", line 659, in run_wsgi_app
    rv = run_wsgi_app(self.application, environ, buffered=buffered)
  File ".virtualenvs/.../site-packages/werkzeug/test.py", line 885, in run_wsgi_app
    buffer.append(next(app_iter))
StopIteration

with response status 200 it works all fine. Is there way how to fix the test?

like image 991
farincz Avatar asked Oct 20 '22 16:10

farincz


1 Answers

The mining of 204 is "no content" at all, it's assume that you're not going to add any body in that response.

like image 96
Israel Avatar answered Oct 31 '22 11:10

Israel