@@ -258,6 +258,76 @@ def test_uvvis_block_lifecycle(admin_client, default_sample_dict, example_data_d
258
258
assert web_block .get ("errors" ) is None
259
259
260
260
261
+ def test_echem_block_lifecycle (admin_client , default_sample_dict , example_data_dir ):
262
+ block_type = "cycle"
263
+
264
+ sample_id = f"test_sample_with_files-{ block_type } -lifecycle"
265
+ sample_data = default_sample_dict .copy ()
266
+ sample_data ["item_id" ] = sample_id
267
+
268
+ response = admin_client .post ("/new-sample/" , json = sample_data )
269
+ assert response .status_code == 201
270
+ assert response .json ["status" ] == "success"
271
+
272
+ response = admin_client .post (
273
+ "/add-data-block/" ,
274
+ json = {
275
+ "block_type" : block_type ,
276
+ "item_id" : sample_id ,
277
+ "index" : 0 ,
278
+ },
279
+ )
280
+
281
+ assert response .status_code == 200 , f"Failed to add { block_type } block: { response .json } "
282
+ assert response .json ["status" ] == "success"
283
+
284
+ block_data = response .json ["new_block_obj" ]
285
+ block_id = block_data ["block_id" ]
286
+
287
+ # Upload multiple echem files
288
+ echem_folder = example_data_dir / "echem"
289
+ example_files = list (echem_folder .glob ("*.mpr" ))[:2 ]
290
+ print ("example_files:" , example_files )
291
+ example_file_ids = []
292
+
293
+ for example_file in example_files :
294
+ with open (example_file , "rb" ) as f :
295
+ response = admin_client .post (
296
+ "/upload-file/" ,
297
+ buffered = True ,
298
+ content_type = "multipart/form-data" ,
299
+ data = {
300
+ "item_id" : sample_id ,
301
+ "file" : [(f , example_file .name )],
302
+ "type" : "application/octet-stream" ,
303
+ "replace_file" : "null" ,
304
+ "relativePath" : "null" ,
305
+ },
306
+ )
307
+ assert response .status_code == 201 , f"Failed to upload { example_file .name } "
308
+ assert response .json ["status" ] == "success"
309
+ file_ids = response .json ["file_id" ]
310
+ example_file_ids .append (file_ids )
311
+
312
+ assert len (example_file_ids ) == 2
313
+
314
+ # Update block with multiple file_ids
315
+ response = admin_client .get (f"/get-item-data/{ sample_id } " )
316
+ assert response .status_code == 200
317
+ item_data = response .json ["item_data" ]
318
+ block_data = item_data ["blocks_obj" ][block_id ]
319
+ block_data ["file_ids" ] = example_file_ids
320
+
321
+ response = admin_client .post ("/update-block/" , json = {"block_data" : block_data })
322
+ assert response .status_code == 200
323
+ web_block = response .json ["new_block_data" ]
324
+ if "bokeh_plot_data" not in web_block :
325
+ print ("Block errors:" , web_block .get ("errors" ))
326
+
327
+ assert "bokeh_plot_data" in web_block
328
+ assert web_block .get ("errors" ) is None
329
+
330
+
261
331
def test_xrd_block_lifecycle (admin_client , default_sample_dict , example_data_dir ):
262
332
from pydatalab .apps .xrd import XRDBlock
263
333
0 commit comments