@@ -330,3 +330,53 @@ def test_unit_replace_children(self):
330330 },
331331 update_receiver .call_args_list [0 ].kwargs ,
332332 )
333+
334+ def test_restore_unit (self ):
335+ """
336+ Test restore a deleted unit.
337+ """
338+ lib = self ._create_library (slug = "containers" , title = "Container Test Library" , description = "Units and more" )
339+ lib_key = LibraryLocatorV2 .from_string (lib ["id" ])
340+
341+ # Create a unit:
342+ create_date = datetime (2024 , 9 , 8 , 7 , 6 , 5 , tzinfo = timezone .utc )
343+ with freeze_time (create_date ):
344+ container_data = self ._create_container (lib ["id" ], "unit" , slug = "u1" , display_name = "Test Unit" )
345+
346+ # Delete the unit
347+ self ._delete_container (container_data ["container_key" ])
348+
349+ create_receiver = mock .Mock ()
350+ LIBRARY_CONTAINER_CREATED .connect (create_receiver )
351+
352+ # Restore container
353+ self ._restore_container (container_data ["container_key" ])
354+ new_container_data = self ._get_container (container_data ["container_key" ])
355+ expected_data = {
356+ "container_key" : "lct:CL-TEST:containers:unit:u1" ,
357+ "container_type" : "unit" ,
358+ "display_name" : "Test Unit" ,
359+ "last_published" : None ,
360+ "published_by" : "" ,
361+ "last_draft_created" : "2024-09-08T07:06:05Z" ,
362+ "last_draft_created_by" : 'Bob' ,
363+ 'has_unpublished_changes' : True ,
364+ 'created' : '2024-09-08T07:06:05Z' ,
365+ 'modified' : '2024-09-08T07:06:05Z' ,
366+ 'collections' : [],
367+ }
368+
369+ self .assertDictContainsEntries (new_container_data , expected_data )
370+
371+ assert create_receiver .call_count == 1
372+ self .assertDictContainsSubset (
373+ {
374+ "signal" : LIBRARY_CONTAINER_CREATED ,
375+ "sender" : None ,
376+ "library_container" : LibraryContainerData (
377+ lib_key ,
378+ container_key = "lct:CL-TEST:containers:unit:u1" ,
379+ ),
380+ },
381+ create_receiver .call_args_list [0 ].kwargs ,
382+ )
0 commit comments