From 4b64e44b5c8f9b13f382fff55f05427c8684532b Mon Sep 17 00:00:00 2001 From: SvyatoslavArtymovych Date: Mon, 24 Apr 2023 11:29:05 +0300 Subject: [PATCH] refactor test util login --- tests/test_auth.py | 6 +++--- tests/utils.py | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/tests/test_auth.py b/tests/test_auth.py index 62f03b1..d33d076 100644 --- a/tests/test_auth.py +++ b/tests/test_auth.py @@ -12,11 +12,11 @@ def test_auth_pages(client): def test_login_and_logout(client): # Access to logout view before login should fail. - response = login(client) + response, _ = login(client) assert b"Login successful." in response.data # Incorrect login credentials should fail. - response = login(client, "sam", "wrongpassword") + response, _ = login(client, "sam", "wrongpassword") assert b"Wrong user ID or password." in response.data # Correct credentials should login - response = login(client) + response, _ = login(client) assert b"Login successful." in response.data diff --git a/tests/utils.py b/tests/utils.py index 3d25bec..0cf4789 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -13,9 +13,11 @@ def create(username=TEST_ADMIN_NAME, password=TEST_ADMIN_PASSWORD): def login(client, username=TEST_ADMIN_NAME, password=TEST_ADMIN_PASSWORD): - return client.post( + user = User.query.filter_by(username=username).first() + response = client.post( "/login", data=dict(user_id=username, password=password), follow_redirects=True ) + return response, user def logout(client):