Final test fixes

This commit is contained in:
Julian Stirling 2025-12-20 16:23:01 +00:00
parent 5d25067a21
commit e85a1d3080
2 changed files with 6 additions and 5 deletions

View file

@ -6,13 +6,14 @@ from socket import gethostname
# Import as ofm server to attempt to minimise confusion with server as a var in other # Import as ofm server to attempt to minimise confusion with server as a var in other
# functions and also FastAPI `Server`. # functions and also FastAPI `Server`.
from openflexure_microscope_server.server import legacy_api from openflexure_microscope_server.server import legacy_api
from openflexure_microscope_server.things.camera import BaseCamera
def test_v2_endpoints(mocker): def test_v2_endpoints(mocker):
"""Check that the expected v2 endpoints are added.""" """Check that the expected v2 endpoints are added."""
mock_server = mocker.Mock() mock_server = mocker.Mock()
# Mock the camera thing to mocke the lores_mjpeg stream get_frame() # Mock the camera thing to mocke the lores_mjpeg stream get_frame()
mock_server.things = {"camera": mocker.Mock()} mock_server.things = {"camera": mocker.Mock(spec=BaseCamera)}
mock_server.things["camera"].lores_mjpeg_stream.grab_frame = mocker.AsyncMock( mock_server.things["camera"].lores_mjpeg_stream.grab_frame = mocker.AsyncMock(
return_value="Mock Frame" return_value="Mock Frame"
) )

View file

@ -10,7 +10,7 @@ from fastapi import FastAPI
from openflexure_microscope_server import server as ofm_server from openflexure_microscope_server import server as ofm_server
from openflexure_microscope_server.things.camera import BaseCamera from openflexure_microscope_server.things.camera import BaseCamera
from .test_server_config import FULL_CONFIG from .test_server_config import SIM_CONFIG
def test_no_config(): def test_no_config():
@ -41,7 +41,7 @@ def test_successful_start(mocker, caplog):
mock_uvicorn_run = mocker.patch("openflexure_microscope_server.server.uvicorn.run") mock_uvicorn_run = mocker.patch("openflexure_microscope_server.server.uvicorn.run")
# Run the mock CLI # Run the mock CLI
ofm_server.serve_from_cli(["-c", FULL_CONFIG]) ofm_server.serve_from_cli(["-c", SIM_CONFIG])
# Check that the server was customised and the run # Check that the server was customised and the run
assert mock_customise.call_count == 1 assert mock_customise.call_count == 1
@ -91,10 +91,10 @@ def test_failed_customise(mocker):
# Running the mock CLI will error # Running the mock CLI will error
with pytest.raises(RuntimeError, match="Can't touch this"): with pytest.raises(RuntimeError, match="Can't touch this"):
ofm_server.serve_from_cli(["-c", FULL_CONFIG]) ofm_server.serve_from_cli(["-c", SIM_CONFIG])
# But with the fallback flag uvicorn run will be run # But with the fallback flag uvicorn run will be run
ofm_server.serve_from_cli(["-c", FULL_CONFIG, "--fallback"]) ofm_server.serve_from_cli(["-c", SIM_CONFIG, "--fallback"])
assert mock_uvicorn_run.call_count == 1 assert mock_uvicorn_run.call_count == 1
# Get the fallback app passed to uvicorn tun # Get the fallback app passed to uvicorn tun