|
| 1 | +import logging |
1 | 2 | import sys |
2 | 3 | from typing import Optional |
| 4 | +from unittest.mock import MagicMock |
3 | 5 | from urllib.parse import urlparse |
4 | 6 |
|
5 | 7 | import pytest |
|
14 | 16 | from murfey.instrument_server import check_for_updates, start_instrument_server |
15 | 17 | from murfey.server.api.bootstrap import pypi as pypi_router, version as version_router |
16 | 18 | from murfey.util.api import url_path_for |
| 19 | +from murfey.util.logging import HTTPSHandler |
17 | 20 |
|
18 | 21 | # Set up a test router with only the essential endpoints |
19 | 22 | app = FastAPI() |
@@ -132,11 +135,28 @@ def test_check_for_updates( |
132 | 135 |
|
133 | 136 | @pytest.mark.parametrize("test_params", start_instrument_server_test_matrix) |
134 | 137 | def test_start_instrument_server( |
135 | | - mocker: MockerFixture, test_params: tuple[Optional[str], Optional[int]] |
| 138 | + mocker: MockerFixture, |
| 139 | + mock_client_configuration, |
| 140 | + test_params: tuple[Optional[str], Optional[int]], |
136 | 141 | ): |
137 | 142 | # Unpack test params |
138 | 143 | host, port = test_params |
139 | 144 |
|
| 145 | + # Patch the 'read_config' function |
| 146 | + _ = mocker.patch( |
| 147 | + "murfey.util.client.read_config", return_value=mock_client_configuration |
| 148 | + ) |
| 149 | + |
| 150 | + # Mock the HTTPSHandler (test it separately in a unit test) |
| 151 | + mock_https_handler_instance = MagicMock() |
| 152 | + mock_https_handler_instance.level = logging.INFO |
| 153 | + mock_https_handler_instance.setLevel.return_value = None |
| 154 | + mock_https_handler = mocker.patch( |
| 155 | + "murfey.util.logging.HTTPSHandler", |
| 156 | + spec=HTTPSHandler, |
| 157 | + ) |
| 158 | + mock_https_handler.return_value = mock_https_handler_instance |
| 159 | + |
140 | 160 | # Patch the Uvicorn Server instance |
141 | 161 | mock_server = mocker.patch("uvicorn.Server") |
142 | 162 | # Disable 'run'; we just want to confirm it's called correctly |
|
0 commit comments