|
1 | 1 | from unittest.mock import ANY |
2 | 2 |
|
3 | 3 | from fastapi.testclient import TestClient |
| 4 | +from pytest import fixture |
4 | 5 | from sqlmodel import Session |
5 | 6 |
|
6 | 7 | from murfey.server.api.auth import validate_instrument_token |
|
43 | 44 |
|
44 | 45 | # app.dependency_overrides[murfey_db] = override_murfey_db |
45 | 46 |
|
46 | | -client = TestClient(app) |
| 47 | + |
| 48 | +@fixture(scope="module") |
| 49 | +def fastapi_client(murfey_db_session): |
| 50 | + # Replace the murfey_db instance in endpoint with properly initialised pytest one |
| 51 | + app.dependency_overrides[murfey_db] = murfey_db_session |
| 52 | + # Disable instrument token validation |
| 53 | + app.dependency_overrides[validate_instrument_token] = lambda: None |
| 54 | + |
| 55 | + with TestClient(app) as client: |
| 56 | + yield client |
47 | 57 |
|
48 | 58 |
|
49 | 59 | def test_movie_count( |
50 | | - murfey_db_session: Session, |
| 60 | + fastapi_client: TestClient, |
| 61 | + murfey_db_session: Session, # From conftest.py |
51 | 62 | ): |
52 | 63 |
|
53 | 64 | # Insert table dependencies |
@@ -111,12 +122,7 @@ def test_movie_count( |
111 | 122 | }, |
112 | 123 | ) |
113 | 124 |
|
114 | | - # Replace the murfey_db instance in endpoint with properly initialised pytest one |
115 | | - app.dependency_overrides[murfey_db] = murfey_db_session |
116 | | - # Disable instrument token validation |
117 | | - app.dependency_overrides[validate_instrument_token] = lambda: None |
118 | | - |
119 | | - response = client.get( |
| 125 | + response = fastapi_client.get( |
120 | 126 | f"{url_path_for('session_control.router', 'count_number_of_movies')}", |
121 | 127 | headers={"Authorization": f"Bearer {ANY}"}, |
122 | 128 | ) |
|
0 commit comments