|
1 | | -from unittest.mock import ANY |
| 1 | +from unittest.mock import ANY, patch |
2 | 2 |
|
3 | 3 | import pytest |
4 | 4 | from fastapi.testclient import TestClient |
5 | 5 | from sqlmodel import Session |
6 | 6 |
|
7 | 7 | from murfey.server.api.auth import validate_instrument_token |
8 | 8 | from murfey.server.main import app |
9 | | -from murfey.server.murfey_db import murfey_db |
10 | 9 | from murfey.util.api import url_path_for |
| 10 | +from murfey.util.config import security_from_file |
11 | 11 | from murfey.util.db import ( |
12 | 12 | AutoProcProgram, |
13 | 13 | DataCollection, |
|
16 | 16 | MurfeyLedger, |
17 | 17 | ProcessingJob, |
18 | 18 | ) |
19 | | -from tests.conftest import ExampleVisit, get_or_create_db_entry |
| 19 | +from tests.conftest import ExampleVisit, get_or_create_db_entry, murfey_db_url |
20 | 20 |
|
21 | 21 | # @pytest.fixture(scope="module") |
22 | 22 | # def test_user(): |
|
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") |
48 | 50 | @pytest.fixture |
49 | | -def fastapi_client(murfey_db_session): |
| 51 | +def fastapi_client( |
| 52 | + mock_get_url, |
| 53 | + mock_get_security_config, |
| 54 | + mock_security_configuration, |
| 55 | + murfey_db_session, |
| 56 | +): |
| 57 | + # 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 |
| 65 | + |
50 | 66 | # Replace the murfey_db instance in endpoint with properly initialised pytest one |
51 | 67 | app.dependency_overrides[murfey_db] = murfey_db_session |
52 | 68 | # Disable instrument token validation |
|
0 commit comments