@@ -15,8 +15,8 @@ def test_register_dc_group_new_dcg(mock_transport, murfey_db_session: Session):
1515 # Request new dcg registration
1616 dcg_params = DCGroupParameters (
1717 experiment_type_id = 44 ,
18- tag = "atlas_tag " ,
19- atlas = "/path/to/Atlas_1.jpg" ,
18+ tag = "/path/to/Sample10/Atlas " ,
19+ atlas = "/path/to/Sample10/Atlas/ Atlas_1.jpg" ,
2020 sample = 10 ,
2121 atlas_pixel_size = 1e-5 ,
2222 )
@@ -34,9 +34,9 @@ def test_register_dc_group_new_dcg(mock_transport, murfey_db_session: Session):
3434 "register" : "data_collection_group" ,
3535 "start_time" : mock .ANY ,
3636 "experiment_type_id" : 44 ,
37- "tag" : "atlas_tag " ,
37+ "tag" : "/path/to/Sample10/Atlas " ,
3838 "session_id" : ExampleVisit .murfey_session_id ,
39- "atlas" : "/path/to/Atlas_1.jpg" ,
39+ "atlas" : "/path/to/Sample10/Atlas/ Atlas_1.jpg" ,
4040 "sample" : 10 ,
4141 "atlas_pixel_size" : 1e-5 ,
4242 "microscope" : "" ,
@@ -57,15 +57,26 @@ def test_register_dc_group_atlas_to_processing(
5757 """
5858 mock_transport .feedback_queue = "mock_feedback_queue"
5959
60- # Make sure dcg is present
61- dcg = DataCollectionGroup (
60+ # Add a processing dcg to ensure this is not touched
61+ proc_dcg = DataCollectionGroup (
6262 id = 1 ,
6363 session_id = ExampleVisit .murfey_session_id ,
64- tag = "atlas_tag" ,
64+ tag = "initial_processing_tag" ,
65+ atlas_id = 90 ,
66+ atlas_pixel_size = 1e-5 ,
67+ sample = 10 ,
68+ atlas = "/path/to/Sample10/Atlas/Atlas_1.jpg" ,
69+ )
70+ murfey_db_session .add (proc_dcg )
71+ # Make sure dcg is present for update
72+ dcg = DataCollectionGroup (
73+ id = 2 ,
74+ session_id = ExampleVisit .murfey_session_id ,
75+ tag = "/path/to/Sample10/Atlas" ,
6576 atlas_id = 90 ,
6677 atlas_pixel_size = 1e-5 ,
6778 sample = 10 ,
68- atlas = "/path/to/Atlas_1.jpg" ,
79+ atlas = "/path/to/Sample10/Atlas/ Atlas_1.jpg" ,
6980 )
7081 murfey_db_session .add (dcg )
7182 murfey_db_session .commit ()
@@ -74,7 +85,7 @@ def test_register_dc_group_atlas_to_processing(
7485 dcg_params = DCGroupParameters (
7586 experiment_type_id = 36 ,
7687 tag = "processing_tag" ,
77- atlas = "/path/to/Atlas_1.jpg" ,
88+ atlas = "/path/to/Sample10/Atlas/ Atlas_1.jpg" ,
7889 sample = 10 ,
7990 atlas_pixel_size = 1e-5 ,
8091 )
@@ -91,14 +102,18 @@ def test_register_dc_group_atlas_to_processing(
91102 {
92103 "register" : "experiment_type_update" ,
93104 "experiment_type_id" : 36 ,
94- "dcgid" : 1 ,
105+ "dcgid" : 2 ,
95106 },
96107 )
97108
98109 # Check that the tag of the data collection group was updated
99- new_dcg = murfey_db_session .exec (
110+ initial_dcg = murfey_db_session .exec (
100111 select (DataCollectionGroup ).where (DataCollectionGroup .id == 1 )
101112 ).one ()
113+ assert initial_dcg .tag == "initial_processing_tag"
114+ new_dcg = murfey_db_session .exec (
115+ select (DataCollectionGroup ).where (DataCollectionGroup .id == 2 )
116+ ).one ()
102117 assert new_dcg .tag == "processing_tag"
103118
104119
@@ -120,16 +135,26 @@ def test_register_dc_group_processing_to_atlas(
120135 atlas_id = 90 ,
121136 atlas_pixel_size = 1e-5 ,
122137 sample = 10 ,
123- atlas = "/path/to/Atlas_1.jpg" ,
138+ atlas = "/path/to/Sample10/Atlas/ Atlas_1.jpg" ,
124139 )
125140 murfey_db_session .add (dcg )
141+ second_dcg = DataCollectionGroup (
142+ id = 2 ,
143+ session_id = ExampleVisit .murfey_session_id ,
144+ tag = "second_processing_tag" ,
145+ atlas_id = 90 ,
146+ atlas_pixel_size = 1e-5 ,
147+ sample = 10 ,
148+ atlas = "/path/to/Sample10/Atlas/Atlas_1.jpg" ,
149+ )
150+ murfey_db_session .add (second_dcg )
126151 murfey_db_session .commit ()
127152
128153 # Request new dcg registration with atlas experiment type and tag
129154 dcg_params = DCGroupParameters (
130155 experiment_type_id = 44 ,
131- tag = "atlas_tag " ,
132- atlas = "/path/to/Atlas_2.jpg" ,
156+ tag = "/path/to/Sample10/Atlas " ,
157+ atlas = "/path/to/Sample10/Atlas/ Atlas_2.jpg" ,
133158 sample = 10 ,
134159 atlas_pixel_size = 1e-4 ,
135160 )
@@ -141,27 +166,104 @@ def test_register_dc_group_processing_to_atlas(
141166 )
142167
143168 # Check request to ispyb for updating the experiment type
144- mock_transport .send .assert_called_once_with (
169+ assert mock_transport .send .call_count == 2
170+ mock_transport .send .assert_any_call (
145171 "mock_feedback_queue" ,
146172 {
147173 "register" : "atlas_update" ,
148174 "atlas_id" : 90 ,
149- "atlas" : "/path/to/Atlas_2.jpg" ,
175+ "atlas" : "/path/to/Sample10/Atlas/ Atlas_2.jpg" ,
150176 "sample" : 10 ,
151177 "atlas_pixel_size" : 1e-4 ,
152178 "dcgid" : 1 ,
153179 "session_id" : ExampleVisit .murfey_session_id ,
154180 },
155181 )
182+ mock_transport .send .assert_any_call (
183+ "mock_feedback_queue" ,
184+ {
185+ "register" : "atlas_update" ,
186+ "atlas_id" : 90 ,
187+ "atlas" : "/path/to/Sample10/Atlas/Atlas_2.jpg" ,
188+ "sample" : 10 ,
189+ "atlas_pixel_size" : 1e-4 ,
190+ "dcgid" : 2 ,
191+ "session_id" : ExampleVisit .murfey_session_id ,
192+ },
193+ )
156194
157195 # Check the data collection group atlas was updated
158196 new_dcg = murfey_db_session .exec (
159197 select (DataCollectionGroup ).where (DataCollectionGroup .id == 1 )
160198 ).one ()
161- assert new_dcg .atlas == "/path/to/Atlas_2.jpg"
199+ second_new_dcg = murfey_db_session .exec (
200+ select (DataCollectionGroup ).where (DataCollectionGroup .id == 1 )
201+ ).one ()
202+ assert new_dcg .atlas == "/path/to/Sample10/Atlas/Atlas_2.jpg"
162203 assert new_dcg .atlas_pixel_size == 1e-4
204+ assert second_new_dcg .atlas == "/path/to/Sample10/Atlas/Atlas_2.jpg"
205+ assert second_new_dcg .atlas_pixel_size == 1e-4
163206 # Check the tag of the data collection group was not updated
164- assert new_dcg .tag != "atlas_tag"
207+ assert new_dcg .tag != "/path/to/Sample10/Atlas"
208+ assert second_new_dcg .tag != "/path/to/Sample10/Atlas"
209+
210+
211+ @mock .patch ("murfey.server.api.workflow._transport_object" )
212+ def test_register_dc_group_new_dcg_old_atlas (
213+ mock_transport , murfey_db_session : Session
214+ ):
215+ """
216+ Test the request to register a new processing type data collection group
217+ in the case where there is already one for that atlas
218+ """
219+ mock_transport .feedback_queue = "mock_feedback_queue"
220+
221+ # Make sure dcg is present
222+ dcg = DataCollectionGroup (
223+ id = 1 ,
224+ session_id = ExampleVisit .murfey_session_id ,
225+ tag = "processing_tag" ,
226+ atlas_id = 90 ,
227+ atlas_pixel_size = 1e-5 ,
228+ sample = 10 ,
229+ atlas = "/path/to/Sample10/Atlas/Atlas_1.jpg" ,
230+ )
231+ murfey_db_session .add (dcg )
232+ murfey_db_session .commit ()
233+
234+ # Request new dcg registration with atlas experiment type and new processing tag
235+ dcg_params = DCGroupParameters (
236+ experiment_type_id = 37 ,
237+ tag = "second_processing_tag" ,
238+ atlas = "/path/to/Sample10/Atlas/Atlas_1.jpg" ,
239+ sample = 10 ,
240+ atlas_pixel_size = 1e-5 ,
241+ )
242+ register_dc_group (
243+ visit_name = "cm12345-6" ,
244+ session_id = ExampleVisit .murfey_session_id ,
245+ dcg_params = dcg_params ,
246+ db = murfey_db_session ,
247+ )
248+
249+ # Check request for registering dcg in ispyb and murfey
250+ mock_transport .send .assert_called_once_with (
251+ "mock_feedback_queue" ,
252+ {
253+ "register" : "data_collection_group" ,
254+ "start_time" : mock .ANY ,
255+ "experiment_type_id" : 37 ,
256+ "tag" : "second_processing_tag" ,
257+ "session_id" : ExampleVisit .murfey_session_id ,
258+ "atlas" : "/path/to/Sample10/Atlas/Atlas_1.jpg" ,
259+ "sample" : 10 ,
260+ "atlas_pixel_size" : 1e-5 ,
261+ "microscope" : "" ,
262+ "proposal_code" : ExampleVisit .proposal_code ,
263+ "proposal_number" : str (ExampleVisit .proposal_number ),
264+ "visit_number" : str (ExampleVisit .visit_number ),
265+ },
266+ )
165267
166268
167269@mock .patch ("murfey.server.api.workflow._transport_object" )
@@ -186,7 +288,7 @@ def test_register_dc_group_new_atlas(mock_transport, murfey_db_session: Session)
186288 dcg_params = DCGroupParameters (
187289 experiment_type_id = 36 ,
188290 tag = "processing_tag" ,
189- atlas = "/path/to/Atlas_2.jpg" ,
291+ atlas = "/path/to/Sample10/Atlas/ Atlas_2.jpg" ,
190292 sample = 10 ,
191293 atlas_pixel_size = 1e-4 ,
192294 )
@@ -204,15 +306,15 @@ def test_register_dc_group_new_atlas(mock_transport, murfey_db_session: Session)
204306 atlas_args = mock_transport .do_insert_atlas .call_args_list
205307 assert len (atlas_args ) == 1
206308 assert atlas_args [0 ][0 ][0 ].dataCollectionGroupId == 1
207- assert atlas_args [0 ][0 ][0 ].atlasImage == "/path/to/Atlas_2.jpg"
309+ assert atlas_args [0 ][0 ][0 ].atlasImage == "/path/to/Sample10/Atlas/ Atlas_2.jpg"
208310 assert atlas_args [0 ][0 ][0 ].pixelSize == 1e-4
209311 assert atlas_args [0 ][0 ][0 ].cassetteSlot == 10
210312
211313 # Check the data collection group atlas was updated
212314 new_dcg = murfey_db_session .exec (
213315 select (DataCollectionGroup ).where (DataCollectionGroup .id == 1 )
214316 ).one ()
215- assert new_dcg .atlas == "/path/to/Atlas_2.jpg"
317+ assert new_dcg .atlas == "/path/to/Sample10/Atlas/ Atlas_2.jpg"
216318 assert new_dcg .sample == 10
217319 assert new_dcg .atlas_pixel_size == 1e-4
218320 assert new_dcg .tag == "processing_tag"
@@ -238,7 +340,7 @@ def test_register_dc_group_new_atlas_with_searchmaps(
238340 atlas_id = 90 ,
239341 atlas_pixel_size = 1e-5 ,
240342 sample = 10 ,
241- atlas = "/path/to/Atlas_1.jpg" ,
343+ atlas = "/path/to/Sample10/Atlas/ Atlas_1.jpg" ,
242344 )
243345 murfey_db_session .add (dcg )
244346 murfey_db_session .commit ()
@@ -271,7 +373,7 @@ def test_register_dc_group_new_atlas_with_searchmaps(
271373 dcg_params = DCGroupParameters (
272374 experiment_type_id = 37 ,
273375 tag = "processing_tag" ,
274- atlas = "/path/to/Atlas_2.jpg" ,
376+ atlas = "/path/to/Sample12/Atlas/ Atlas_2.jpg" ,
275377 sample = 12 ,
276378 atlas_pixel_size = 1e-4 ,
277379 )
@@ -288,7 +390,7 @@ def test_register_dc_group_new_atlas_with_searchmaps(
288390 {
289391 "register" : "atlas_update" ,
290392 "atlas_id" : 90 ,
291- "atlas" : "/path/to/Atlas_2.jpg" ,
393+ "atlas" : "/path/to/Sample12/Atlas/ Atlas_2.jpg" ,
292394 "sample" : 12 ,
293395 "atlas_pixel_size" : 1e-4 ,
294396 "dcgid" : 1 ,
@@ -300,7 +402,7 @@ def test_register_dc_group_new_atlas_with_searchmaps(
300402 new_dcg = murfey_db_session .exec (
301403 select (DataCollectionGroup ).where (DataCollectionGroup .id == dcg .id )
302404 ).one ()
303- assert new_dcg .atlas == "/path/to/Atlas_2.jpg"
405+ assert new_dcg .atlas == "/path/to/Sample12/Atlas/ Atlas_2.jpg"
304406 assert new_dcg .sample == 12
305407 assert new_dcg .atlas_pixel_size == 1e-4
306408 assert new_dcg .tag == "processing_tag"
0 commit comments