Skip to content

Commit c888c75

Browse files
committed
Added test for 'validate_user' helper function
1 parent d220658 commit c888c75

1 file changed

Lines changed: 35 additions & 2 deletions

File tree

tests/server/api/test_auth_api.py

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
validate_frontend_session_access,
1515
validate_session_against_visit,
1616
validate_token,
17+
validate_user,
1718
validate_user_instrument_access,
1819
)
1920
from murfey.util.db import MurfeyUser, Session as MurfeySession
@@ -475,8 +476,40 @@ def test_verify_password():
475476
pass
476477

477478

478-
def test_validate_user():
479-
pass
479+
@pytest.mark.parametrize(
480+
"test_params",
481+
( # User to query | Expected outcome
482+
("test_user", True),
483+
("some_user", False),
484+
),
485+
)
486+
def test_validate_user(
487+
mocker: MockerFixture,
488+
murfey_db_session: SQLModelSession,
489+
test_params: tuple[str, bool],
490+
):
491+
# Unpack test params
492+
user_to_query, expected_result = test_params
493+
494+
# Add a user to the test database
495+
user_entry = MurfeyUser(
496+
username="test_user",
497+
hashed_password="asdfghjkl",
498+
)
499+
murfey_db_session.add(user_entry)
500+
murfey_db_session.commit()
501+
502+
# Mock the 'verify_password' function
503+
mocker.patch("murfey.server.api.auth.verify_password", return_value=True)
504+
505+
# Patch the Session call with the test database
506+
mock_session_context = MagicMock()
507+
mock_session_context.__enter__.return_value = murfey_db_session
508+
mock_session_context.__exit__.return_value = None
509+
mocker.patch("murfey.server.api.auth.Session", return_value=mock_session_context)
510+
511+
# Run the function and check that the outocome is as expected
512+
assert validate_user(user_to_query, "dummypassword") == expected_result
480513

481514

482515
def test_create_access_token():

0 commit comments

Comments
 (0)