fix auth tests

This commit is contained in:
SvyatoslavArtymovych 2023-06-12 15:19:16 +03:00
parent 806dd8a706
commit f0de4a1f32
2 changed files with 8 additions and 3 deletions

View File

@ -15,7 +15,7 @@ def test_login_and_logout(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", create_user_if_not_exists=False)
assert b"Wrong user ID or password." in response.data
# Correct credentials should login
response, _ = login(client)

View File

@ -21,9 +21,14 @@ def create(username=TEST_ADMIN_NAME, password=TEST_ADMIN_PASSWORD):
return user
def login(client, username=TEST_ADMIN_NAME, password=TEST_ADMIN_PASSWORD):
def login(
client,
username=TEST_ADMIN_NAME,
password=TEST_ADMIN_PASSWORD,
create_user_if_not_exists=True,
):
user = m.User.query.filter_by(username=username).first()
if not user:
if create_user_if_not_exists and not user:
user = create(username, password)
response = client.post(