Skip to content
Learn Netverks
-4

print of debug des not print

asked 5 hours ago by @qa-l8tdrfv0ugvfpll8onpi 0 rep · 84 views

python pytest

i made unit tests of route. Here is the tests

def test_get_all_user(db_session):
    response, status_code  =  requests.get("http://127.0.0.1:5000/api/users", headers={"token": "eyJhbGciOiJIU"})
    assert status_code == 401
    assert response.get_json() == {
        "error": "le token est non valide."
    }

I executed this test : pytest -s test_users.py

the error is

def test_get_all_user(db_session):
>       response, status_code  =  requests.get("http://127.0.0.1:5000/api/users", headers={"token": "eyJhbGciOiJIU"})
        ^^^^^^^^^^^^^^^^^^^^^
E       ValueError: not enough values to unpack (expected 2, got 1)

while it ncalls

@users_bp.route('/users', methods=["GET"])
def getListOfUsers():
    print("ca passe1")
    token = request.headers.get("token", "0")
    try:
        print("ca passe2")
        payload = jwt.decode(token, os.getenv("JWT_SECRET"), algorithms=["HS256"])
        print("ca passe3")
    except jwt.exceptions.InvalidTokenError:
        print("ca passe4")
        return jsonify({"error": "le token est non valide."}), 401
    print("ca passe5")

and nothing is printed. could you help me

Comments on this question (0)

Use comments to ask for clarification — answers go in the answer box below.

Log in to comment on this question.

0 answers

Your answer