Skip to content

Commit fe10c62

Browse files
committed
Use the FastAPI TestClient to test the 'upload_gain_reference' endpoint, now that we know how to do so
1 parent 99f216f commit fe10c62

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

tests/instrument_server/test_api.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@
88
from fastapi.testclient import TestClient
99
from pytest_mock import MockerFixture
1010

11-
from murfey.instrument_server.api import GainReference, _get_murfey_url
11+
from murfey.instrument_server.api import _get_murfey_url
1212
from murfey.instrument_server.api import router as client_router
13-
from murfey.instrument_server.api import upload_gain_reference, validate_session_token
13+
from murfey.instrument_server.api import validate_session_token
1414
from murfey.util import posix_path
1515
from murfey.util.api import url_path_for
1616

@@ -105,7 +105,7 @@ def test_upload_gain_reference(
105105
):
106106
# Unpack test parameters and define other ones
107107
(rsync_url_setting,) = test_params
108-
server_url = "http://0.0.0.0:8000"
108+
server_url = "https://murfey.server.test"
109109
instrument_name = "murfey"
110110
session_id = 1
111111

@@ -142,13 +142,18 @@ def test_upload_gain_reference(
142142
"visit_path": visit_path,
143143
"gain_destination_dir": gain_dest_dir,
144144
}
145-
result = upload_gain_reference(
145+
146+
# Set up instrument server test client
147+
client_server = set_up_test_client(session_id=session_id)
148+
149+
# Poke the endpoint with the expected data
150+
url_path = url_path_for(
151+
"api.router",
152+
"upload_gain_reference",
146153
instrument_name=instrument_name,
147154
session_id=session_id,
148-
gain_reference=GainReference(
149-
**payload,
150-
),
151155
)
156+
response = client_server.post(url_path, json=payload)
152157

153158
# Check that the machine config request was called
154159
machine_config_url = f"{server_url}{url_path_for('session_control.router', 'machine_info_by_instrument', instrument_name=instrument_name)}"
@@ -176,4 +181,4 @@ def test_upload_gain_reference(
176181
)
177182

178183
# Check that the function ran through to completion successfully
179-
assert result == {"success": True}
184+
assert response.json() == {"success": True}

0 commit comments

Comments
 (0)