From 348c2271c62f54df94b779ebdbd9e206b9dde226 Mon Sep 17 00:00:00 2001 From: Son Nguyen Kim Date: Fri, 6 Aug 2021 08:46:34 +0200 Subject: [PATCH] fix test --- tests/oauth/test_authorize.py | 20 +++++++++++++------- tests/test_jose_utils.py | 34 ++++++++++++++++------------------ 2 files changed, 29 insertions(+), 25 deletions(-) diff --git a/tests/oauth/test_authorize.py b/tests/oauth/test_authorize.py index c045e425..dcf44bf1 100644 --- a/tests/oauth/test_authorize.py +++ b/tests/oauth/test_authorize.py @@ -6,7 +6,7 @@ from flask import url_for from app.extensions import db from app.jose_utils import verify_id_token, decode_id_token -from app.models import Client, User +from app.models import Client, User, ClientUser from app.oauth.views.authorize import ( get_host_name_and_scheme, generate_access_token, @@ -192,14 +192,16 @@ def test_authorize_code_flow_no_openid_scope(flask_client): assert not r.json["scope"] assert r.json["token_type"] == "Bearer" + client_user = ClientUser.first() + assert r.json["user"] == { "avatar_url": None, "client": "test client", "email": "x@y.z", "email_verified": True, - "id": 1, + "id": client_user.id, "name": "AB CD", - "sub": "1", + "sub": str(client_user.id), } @@ -280,14 +282,16 @@ def test_authorize_code_flow_with_openid_scope(flask_client): assert r.json["scope"] == "openid" assert r.json["token_type"] == "Bearer" + client_user = ClientUser.first() + assert r.json["user"] == { "avatar_url": None, "client": "test client", "email": "x@y.z", "email_verified": True, - "id": 1, + "id": client_user.id, "name": "AB CD", - "sub": "1", + "sub": str(client_user.id), } # id_token must be returned @@ -601,14 +605,16 @@ def test_authorize_code_id_token_flow(flask_client): assert not r.json["scope"] assert r.json["token_type"] == "Bearer" + client_user = ClientUser.first() + assert r.json["user"] == { "avatar_url": None, "client": "test client", "email": "x@y.z", "email_verified": True, - "id": 1, + "id": client_user.id, "name": "AB CD", - "sub": "1", + "sub": str(client_user.id), } # id_token must be returned diff --git a/tests/test_jose_utils.py b/tests/test_jose_utils.py index bd173913..557beb66 100644 --- a/tests/test_jose_utils.py +++ b/tests/test_jose_utils.py @@ -3,28 +3,26 @@ from app.jose_utils import make_id_token, verify_id_token from app.models import ClientUser, User, Client -def test_encode_decode(flask_app): - with flask_app.app_context(): - user = User.create( - email="a@b.c", password="password", name="Test User", activated=True - ) - db.session.commit() +def test_encode_decode(flask_client): + user = User.create( + email="a@b.c", password="password", name="Test User", activated=True + ) + db.session.commit() - client1 = Client.create_new(name="Demo", user_id=user.id) - client1.oauth_client_id = "client-id" - client1.oauth_client_secret = "client-secret" - db.session.commit() + client1 = Client.create_new(name="Demo", user_id=user.id) + client1.oauth_client_id = "client-id" + client1.oauth_client_secret = "client-secret" + db.session.commit() - client_user = ClientUser.create(client_id=client1.id, user_id=user.id) - db.session.commit() + client_user = ClientUser.create(client_id=client1.id, user_id=user.id) + db.session.commit() - jwt_token = make_id_token(client_user) + jwt_token = make_id_token(client_user) - assert type(jwt_token) is str - assert verify_id_token(jwt_token) + assert type(jwt_token) is str + assert verify_id_token(jwt_token) -def test_db_tear_down(flask_app): +def test_db_tear_down(flask_client): """make sure the db is reset after each test""" - with flask_app.app_context(): - assert len(ClientUser.filter_by().all()) == 0 + assert len(ClientUser.filter_by().all()) == 0