Skip to content

Commit cfc48cb

Browse files
committed
Check contents of request.get() call
1 parent 4a1548e commit cfc48cb

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

tests/instrument_server/test_api.py

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,24 @@
1818

1919
@mark.parametrize("test_params", test_upload_gain_reference_params_matrix)
2020
@patch("murfey.instrument_server.api.subprocess")
21+
@patch("murfey.instrument_server.api.tokens")
2122
@patch("murfey.instrument_server.api._get_murfey_url")
2223
@patch("murfey.instrument_server.api.requests")
2324
def test_upload_gain_reference(
2425
mock_request,
2526
mock_get_server_url,
27+
mock_tokens,
2628
mock_subprocess,
2729
test_params: tuple[Optional[str]],
2830
):
2931

30-
# Create a mock machine config base on the test params
32+
# Unpack test parameters and define other ones
3133
(rsync_url_setting,) = test_params
3234
server_url = "http://0.0.0.0:8000"
35+
instrument_name = "murfey"
36+
session_id = 1
37+
38+
# Create a mock machine config base on the test params
3339
rsync_module = "data"
3440
gain_ref_dir = "C:/ProgramData/Gatan/Gain Reference"
3541
mock_machine_config = {
@@ -48,7 +54,9 @@ def test_upload_gain_reference(
4854
mock_subprocess.run.return_value = Mock(
4955
returncode=0, stderr="An error has occurred."
5056
)
51-
57+
mock_tokens = {
58+
session_id: "hello",
59+
}
5260
# Construct payload and pass request to function
5361
gain_ref_file = f"{gain_ref_dir}/gain.mrc"
5462
visit_path = "2025/aa00000-0"
@@ -59,15 +67,19 @@ def test_upload_gain_reference(
5967
"gain_destination_dir": gain_dest_dir,
6068
}
6169
result = upload_gain_reference(
62-
instrument_name="murfey",
63-
session_id=1,
70+
instrument_name=instrument_name,
71+
session_id=session_id,
6472
gain_reference=GainReference(
6573
**payload,
6674
),
6775
)
6876

6977
# Check that the machine config request was called
70-
mock_request.get.assert_called_once()
78+
machine_config_url = f"{server_url}/instruments/{instrument_name}/machine"
79+
mock_request.get.assert_called_once_with(
80+
machine_config_url,
81+
headers={"Authorization": f"Bearer {mock_tokens[session_id]}"},
82+
)
7183

7284
# Check that the subprocess was run with the expected arguments
7385
# If no rsync_url key is provided, or rsync_url key is empty,

0 commit comments

Comments
 (0)