|
45 | 45 | # app.dependency_overrides[murfey_db] = override_murfey_db |
46 | 46 |
|
47 | 47 |
|
48 | | -@patch("murfey.server.murfey_db.get_security_config") |
49 | | -@patch("murfey.server.murfey_db.url") |
50 | 48 | @pytest.fixture |
51 | | -def fastapi_client( |
52 | | - mock_get_url, |
53 | | - mock_get_security_config, |
| 49 | +def fastapi_test_client( |
54 | 50 | mock_security_configuration, |
55 | 51 | murfey_db_session, |
56 | 52 | ): |
57 | 53 | # Set up mock security configs for |
58 | | - mock_get_url.return_value = murfey_db_url |
59 | | - mock_get_security_config.return_value = security_from_file( |
60 | | - mock_security_configuration |
61 | | - ) |
62 | | - |
63 | | - # Defer import of 'murfey_db' until after mocks are configured |
64 | | - from murfey.server.murfey_db import murfey_db |
| 54 | + with ( |
| 55 | + patch( |
| 56 | + "murfey.server.murfey_db.get_security_config" |
| 57 | + ) as mock_get_security_config, |
| 58 | + patch("murfey.server.murfey_db.url") as mock_get_url, |
| 59 | + ): |
| 60 | + |
| 61 | + # Defer import of 'murfey_db' until after mocks are configured |
| 62 | + mock_get_url.return_value = murfey_db_url |
| 63 | + mock_get_security_config.return_value = security_from_file( |
| 64 | + mock_security_configuration |
| 65 | + ) |
| 66 | + from murfey.server.murfey_db import murfey_db |
65 | 67 |
|
66 | | - # Replace the murfey_db instance in endpoint with properly initialised pytest one |
67 | | - app.dependency_overrides[murfey_db] = murfey_db_session |
68 | | - # Disable instrument token validation |
69 | | - app.dependency_overrides[validate_instrument_token] = lambda: None |
| 68 | + # Replace the murfey_db instance in endpoint with properly initialised pytest one |
| 69 | + app.dependency_overrides[murfey_db] = murfey_db_session |
| 70 | + # Disable instrument token validation |
| 71 | + app.dependency_overrides[validate_instrument_token] = lambda: None |
70 | 72 |
|
71 | | - with TestClient(app) as client: |
72 | | - yield client |
| 73 | + with TestClient(app) as client: |
| 74 | + yield client |
73 | 75 |
|
74 | 76 |
|
75 | 77 | def test_movie_count( |
76 | | - fastapi_client: TestClient, |
| 78 | + fastapi_test_client: TestClient, |
77 | 79 | murfey_db_session: Session, # From conftest.py |
78 | 80 | ): |
79 | 81 |
|
@@ -138,7 +140,7 @@ def test_movie_count( |
138 | 140 | }, |
139 | 141 | ) |
140 | 142 |
|
141 | | - response = fastapi_client.get( |
| 143 | + response = fastapi_test_client.get( |
142 | 144 | f"{url_path_for('session_control.router', 'count_number_of_movies')}", |
143 | 145 | headers={"Authorization": f"Bearer {ANY}"}, |
144 | 146 | ) |
|
0 commit comments