@@ -33,10 +33,7 @@ def test_atlas_context_mrc(mock_capture_post, tmp_path):
3333 atlas_mrc .parent .mkdir (parents = True )
3434 atlas_mrc .touch ()
3535
36- context .post_transfer (
37- atlas_mrc ,
38- environment = env ,
39- )
36+ context .post_transfer (atlas_mrc , environment = env )
4037 mock_capture_post .assert_called_once_with (
4138 base_url = "http://localhost:8000" ,
4239 router_name = "session_control.spa_router" ,
@@ -72,10 +69,7 @@ def test_atlas_context_xml(mock_capture_post, tmp_path):
7269 "</numericValue></x></pixelSize></SpatialScale></MicroscopeImage>"
7370 )
7471
75- context .post_transfer (
76- atlas_xml ,
77- environment = env ,
78- )
72+ context .post_transfer (atlas_xml , environment = env )
7973 dcg_data = {
8074 "experiment_type_id" : 44 , # Atlas
8175 "tag" : str (atlas_xml .parent ),
@@ -95,3 +89,87 @@ def test_atlas_context_xml(mock_capture_post, tmp_path):
9589 session_id = 1 ,
9690 data = dcg_data ,
9791 )
92+
93+
94+ @patch ("murfey.client.contexts.atlas.capture_post" )
95+ def test_atlas_context_dm (mock_capture_post , tmp_path ):
96+ env = MurfeyInstanceEnvironment (
97+ url = urlparse ("http://localhost:8000" ),
98+ client_id = 0 ,
99+ sources = [tmp_path / "cm12345-6" ],
100+ default_destinations = {
101+ tmp_path / "cm12345-6" : f"{ tmp_path } /destination/cm12345-6"
102+ },
103+ instrument_name = "m01" ,
104+ visit = "cm12345-6" ,
105+ murfey_session = 1 ,
106+ acquisition_uuid = "uuid1" ,
107+ )
108+
109+ # Write sample dm file
110+ atlas_dm = tmp_path / "cm12345-6/Supervisor_atlas/Sample2/Atlas/Atlas.dm"
111+ atlas_dm .parent .mkdir (parents = True )
112+ grid_square_values = (
113+ "<value><b:PositionOnTheAtlas>"
114+ "<c:Center><d:x>1200</d:x><d:y>1500</d:y></c:Center>"
115+ "<c:Physical><d:x>2</d:x><d:y>3</d:y></c:Physical>"
116+ "<c:Size><d:width>130</d:width><d:height>560</d:height></c:Size>"
117+ "<c:Rotation>0.14</c:Rotation>"
118+ "</b:PositionOnTheAtlas></value>"
119+ )
120+ with open (atlas_dm , "w" ) as new_xml :
121+ new_xml .write (
122+ "<AtlasSessionXml><Atlas><TilesEfficient><_items>"
123+ # First tile with two grid squares
124+ "<TileXml><Nodes><KeyValuePairs><KeyValuePairOfintNodeXml1>"
125+ f"<key>101</key>{ grid_square_values } "
126+ "</KeyValuePairOfintNodeXml1><KeyValuePairOfintNodeXml1>"
127+ f"<key>102</key>{ grid_square_values } "
128+ "</KeyValuePairOfintNodeXml1></KeyValuePairs></Nodes></TileXml>"
129+ # Second tile with two grid squares
130+ "<TileXml><Nodes><KeyValuePairs><KeyValuePairOfintNodeXml1>"
131+ f"<key>103</key>{ grid_square_values } "
132+ "</KeyValuePairOfintNodeXml1><KeyValuePairOfintNodeXml1>"
133+ f"<key>104</key>{ grid_square_values } "
134+ "</KeyValuePairOfintNodeXml1></KeyValuePairs></Nodes></TileXml>"
135+ # Close all
136+ "</_items></TilesEfficient></Atlas></AtlasSessionXml>"
137+ )
138+
139+ context = AtlasContext ("tomo" , tmp_path , {}, "token" )
140+ context .post_transfer (atlas_dm , environment = env )
141+
142+ assert mock_capture_post .call_count == 5
143+ mock_capture_post .assert_any_call (
144+ base_url = "http://localhost:8000" ,
145+ router_name = "session_control.spa_router" ,
146+ function_name = "register_grid_square" ,
147+ token = "token" ,
148+ instrument_name = "m01" ,
149+ session_id = 1 ,
150+ gsid = 101 ,
151+ data = {
152+ "tag" : str (atlas_dm .parent ),
153+ "x_location" : 1200 ,
154+ "y_location" : 1500 ,
155+ "x_stage_position" : 2e9 ,
156+ "y_stage_position" : 3e9 ,
157+ "width" : 130 ,
158+ "height" : 560 ,
159+ "angle" : 0.14 ,
160+ },
161+ )
162+ mock_capture_post .assert_any_call (
163+ base_url = "http://localhost:8000" ,
164+ router_name = "session_control.spa_router" ,
165+ function_name = "register_atlas" ,
166+ token = "token" ,
167+ instrument_name = "m01" ,
168+ session_id = 1 ,
169+ data = {
170+ "name" : "cm12345-6-sample-2" ,
171+ "acquisition_uuid" : "uuid1" ,
172+ "register_grid" : True ,
173+ "tag" : str (atlas_dm .parent ),
174+ },
175+ )
0 commit comments