@@ -250,6 +250,7 @@ def test_xrd_block_lifecycle(admin_client, default_sample_dict):
250250    item_data  =  response .json ["item_data" ]
251251    block_data  =  item_data ["blocks_obj" ][block_id ]
252252    block_data ["file_id" ] =  file_id 
253+     block_data ["wavelength" ] =  2.0 
253254
254255    response  =  admin_client .post (
255256        "/update-block/" , json = {"block_data" : block_data , "save_to_db" : True }
@@ -258,16 +259,30 @@ def test_xrd_block_lifecycle(admin_client, default_sample_dict):
258259    web_block  =  response .json ["new_block_data" ]
259260    assert  "bokeh_plot_data"  in  web_block 
260261    assert  "processed_data"  in  web_block 
262+     assert  web_block ["wavelength" ] ==  2.0 
261263    assert  "peak_data"  in  web_block ["processed_data" ]
262264    assert  "file_id"  in  web_block 
263265    assert  web_block ["file_id" ] ==  file_id 
264266    assert  web_block .get ("errors" ) is  None 
265267
266268    block  =  XRDBlock .from_web (web_block )
267269    db  =  block .to_db ()
270+     # 'computed' keys should be dropped when loading from web 
268271    assert  "bokeh_plot_data"  not  in db 
269-     assert  "processed_data"  in  db 
270-     assert  "peak_data"  in  db ["processed_data" ]
272+     assert  "processed_data"  not  in db 
273+     assert  db ["wavelength" ] ==  2.0 
274+ 
275+     # But they should still be in the database 
276+     response  =  admin_client .get (f"/get-item-data/{ sample_id }  )
277+     assert  response .status_code  ==  200 
278+ 
279+     item_data  =  response .json ["item_data" ]
280+     assert  response .json ["status" ] ==  "success" 
281+     assert  "blocks_obj"  in  item_data 
282+     block  =  item_data ["blocks_obj" ][block_id ]
283+     assert  "processed_data"  in  block 
284+     assert  "peak_data"  in  block ["processed_data" ]
285+     assert  block ["wavelength" ] ==  2.0 
271286
272287
273288def  test_comment_block_manipulation (admin_client , default_sample_dict , database ):
@@ -313,6 +328,7 @@ def test_comment_block_manipulation(admin_client, default_sample_dict, database)
313328    # Check that this result was actually stored 
314329    response  =  admin_client .get (f"/get-item-data/{ sample_id }  )
315330    assert  response .status_code  ==  200 
331+     item_data  =  response .json ["item_data" ]
316332    assert  response .json ["status" ] ==  "success" 
317333    assert  (
318334        response .json ["item_data" ]["blocks_obj" ][block_id ]["freeform_comment" ]
@@ -323,20 +339,46 @@ def test_comment_block_manipulation(admin_client, default_sample_dict, database)
323339    # Try to add some bad data 
324340    block_data ["bokeh_plot_data" ] =  {"bokeh" : "json" }
325341    block_data ["random_new_key" ] =  "test new key" 
342+     block_data ["freeform_comment" ] =  "This is a test comment block with extra data." 
326343    response  =  admin_client .post ("/update-block/" , json = {"block_data" : block_data })
327344    assert  response .status_code  ==  200 
328345    assert  response .json ["status" ] ==  "success" 
329346    assert  response .json ["new_block_data" ]["blocktype" ] ==  block_type 
330-     assert  response .json ["new_block_data" ]["freeform_comment" ] ==  "This is a test comment block." 
347+     assert  (
348+         response .json ["new_block_data" ]["freeform_comment" ]
349+         ==  "This is a test comment block with extra data." 
350+     )
331351    assert  response .json ["new_block_data" ]["title" ] ==  "Test Comment Block" 
332352    assert  "bokeh_plot_data"  not  in response .json ["new_block_data" ]
333-     assert  "random_new_key"  not  in response .json ["new_block_data" ]
353+ 
354+     # Extra random keys will be in the response (in case they are parameters for the block that are not yet handled, 
355+     # but they will not be stored in the database) 
356+     assert  "random_new_key"  in  response .json ["new_block_data" ]
334357
335358    raw_item  =  database .items .find_one ({"item_id" : sample_id })
336359    assert  raw_item 
337-     assert  "bokeh_plot_data"  not  in raw_item 
338-     assert  "random_new_key"  not  in raw_item 
339-     assert  "errors"  not  in raw_item 
360+     raw_block  =  raw_item ["blocks_obj" ][block_id ]
361+     assert  "bokeh_plot_data"  not  in raw_block 
362+     # assert "random_new_key" not in raw_block 
363+     assert  "errors"  not  in raw_block 
364+ 
365+     # Finally, try to update using the save-item endpoint, and make sure any bad data gets stripped out 
366+     item_data ["blocks_obj" ][block_id ]["bokeh_plot_data" ] =  {"bokeh" : "json" }
367+     item_data ["blocks_obj" ][block_id ]["random_new_key" ] =  "test new key again" 
368+     item_data ["blocks_obj" ][block_id ]["freeform_comment" ] =  "This is the latest test comment." 
369+ 
370+     admin_client .post ("/save-item/" , json = {"item_id" : sample_id , "data" : item_data })
371+     assert  response .status_code  ==  200 
372+ 
373+     response  =  admin_client .get (f"/get-item-data/{ sample_id }  )
374+     assert  response .status_code  ==  200 
375+     assert  response .json ["status" ] ==  "success" 
376+     item_data  =  response .json ["item_data" ]
377+     block  =  item_data ["blocks_obj" ][block_id ]
378+ 
379+     assert  block ["freeform_comment" ] ==  "This is the latest test comment." 
380+     assert  block .get ("bokeh_plot_data" ) is  None 
381+     assert  block ["random_new_key" ] ==  "test new key again" 
340382
341383
342384@pytest .mark .parametrize ( 
0 commit comments