refactor test util login

This commit is contained in:
SvyatoslavArtymovych 2023-04-24 11:29:05 +03:00
parent 627179102b
commit 4b64e44b5c
2 changed files with 6 additions and 4 deletions

View File

@ -12,11 +12,11 @@ def test_auth_pages(client):
def test_login_and_logout(client): def test_login_and_logout(client):
# Access to logout view before login should fail. # Access to logout view before login should fail.
response = login(client) response, _ = login(client)
assert b"Login successful." in response.data assert b"Login successful." in response.data
# Incorrect login credentials should fail. # 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 assert b"Wrong user ID or password." in response.data
# Correct credentials should login # Correct credentials should login
response = login(client) response, _ = login(client)
assert b"Login successful." in response.data assert b"Login successful." in response.data

View File

@ -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): 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 "/login", data=dict(user_id=username, password=password), follow_redirects=True
) )
return response, user
def logout(client): def logout(client):