Answer the question
In order to leave comments, you need to log in
Why does 'Response' object has no attribute 'items' error in tests?
The test itself
@pytest.fixture
def client():
app.config['TESTING'] = True
with app.test_client() as cl:
with app.app_context():
yield cl
def test_auth(client):
payload = {
'username': 'testing',
'password': 'hard_pass'
}
resp = client.post('/login', data=jsonify(payload))
assert resp.status_code == 200
@app.route('/login', methods=['POST'])
def login():
return 'This is your login'
d = <Response 46 bytes [200 OK]>, args = (), kwargs = {}
> iteritems = lambda d, *args, **kwargs: iter(d.items(*args, **kwargs))
E AttributeError: 'Response' object has no attribute 'items'
blog_env\lib\site-packages\werkzeug\_compat.py:135: AttributeError
Answer the question
In order to leave comments, you need to log in
The problem itself was with
data=jsonify(payload)
jsonify(payload) formed
. It was necessary to immediately pay attention to this, because the code did not go further than client.post.
Removed jsonify and the test was successful.
<Response 46 bytes [200 OK]>
because the functions decorated with @app.route should return a Response object
in short like this is correct
return Response("This is your login", status=200, content_type="text/plain")
return jsonify({"message": "This is your login"}), 200
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question