-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_register_data_collection_group.py
More file actions
86 lines (77 loc) · 2.84 KB
/
test_register_data_collection_group.py
File metadata and controls
86 lines (77 loc) · 2.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
from unittest.mock import MagicMock
import pytest
from pytest_mock import MockerFixture
from murfey.workflows.register_data_collection_group import run
from tests.conftest import ExampleVisit
register_data_collection_group_params_matrix = (
# ISPyB session ID | # DCG search result | # DCG insert result | # Atlas insert result
(0, 0, 0, 0),
(0, 0, 0, None),
(0, 0, None, 0),
(0, 0, None, None),
(0, None, 0, 0),
(0, None, 0, None),
(0, None, None, 0),
(0, None, None, None),
(None, 0, 0, 0),
(None, 0, 0, None),
(None, 0, None, 0),
(None, 0, None, None),
(None, None, 0, 0),
(None, None, 0, None),
(None, None, None, 0),
(None, None, None, None),
)
@pytest.mark.parametrize("test_params", register_data_collection_group_params_matrix)
def test_run(
mocker: MockerFixture,
test_params: tuple[int | None, int | None, int | None, int | None],
):
# Unpack test params
(ispyb_session_id, dcg_result, insert_dcg, insert_atlas) = test_params
# Mock the transport object functions
mock_transport_object = mocker.patch(
"murfey.workflows.register_data_collection_group._transport_object"
)
mock_transport_object.do_insert_data_collection_group.return_value = {
"return_value": insert_dcg,
}
mock_transport_object.do_insert_atlas.return_value = {"return_value": insert_atlas}
# Mock the 'get_session_id' return value
mock_get_session_id = mocker.patch(
"murfey.workflows.register_data_collection_group.get_session_id"
)
mock_get_session_id.return_value = ispyb_session_id
# Mock the Murfey database
mock_murfey_db = MagicMock()
mock_dcg = MagicMock()
mock_dcg.id = dcg_result
mock_murfey_db.exec.return_value.all.return_value = (
[mock_dcg] if dcg_result is not None else []
)
# Run the function and check the results and calls
message = {
"microscope": "test",
"proposal_code": ExampleVisit.proposal_code,
"proposal_number": ExampleVisit.proposal_number,
"visit_number": ExampleVisit.visit_number,
"session_id": ExampleVisit.murfey_session_id,
"tag": "some_text",
"experiment_type_id": 0,
"atlas": "some_file",
"atlas_pixel_size": 1e-9,
"sample": 0,
}
result = run(message=message, murfey_db=mock_murfey_db)
if dcg_result is not None:
assert result == {"success": True}
else:
if ispyb_session_id is not None:
mock_transport_object.do_insert_data_collection_group.assert_called_once()
if insert_dcg is not None:
mock_transport_object.do_insert_atlas.assert_called_once()
assert result == {"success": True}
else:
assert result == {"success": False, "requeue": True}
else:
assert result == {"success": True}