|
14 | 14 | validate_frontend_session_access, |
15 | 15 | validate_session_against_visit, |
16 | 16 | validate_token, |
| 17 | + validate_user, |
17 | 18 | validate_user_instrument_access, |
18 | 19 | ) |
19 | 20 | from murfey.util.db import MurfeyUser, Session as MurfeySession |
@@ -475,8 +476,40 @@ def test_verify_password(): |
475 | 476 | pass |
476 | 477 |
|
477 | 478 |
|
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 |
480 | 513 |
|
481 | 514 |
|
482 | 515 | def test_create_access_token(): |
|
0 commit comments