@@ -508,6 +508,73 @@ def test_sample_sheet_map_over_preserves_columns(self, history_id):
508508 ], f"Expected [3, 'control'], got { output_elements [2 ]['columns' ]} "
509509 assert output_elements [2 ]["element_identifier" ] == "sample3"
510510
511+ def test_copy_sample_sheet_collection (self , history_id ):
512+ """Test that copying a sample sheet collection preserves columns metadata."""
513+ # Create a sample sheet collection with columns metadata
514+ contents = [
515+ ("sample1" , "content1" ),
516+ ("sample2" , "content2" ),
517+ ]
518+ sample_sheet_identifiers = self .dataset_collection_populator .list_identifiers (history_id , contents )
519+ payload = dict (
520+ name = "original sample sheet" ,
521+ instance_type = "history" ,
522+ history_id = history_id ,
523+ element_identifiers = sample_sheet_identifiers ,
524+ collection_type = "sample_sheet" ,
525+ column_definitions = [
526+ {"type" : "int" , "name" : "replicate" , "optional" : False },
527+ {"type" : "string" , "name" : "condition" , "optional" : False },
528+ ],
529+ rows = {
530+ "sample1" : [1 , "control" ],
531+ "sample2" : [2 , "treatment" ],
532+ },
533+ )
534+ create_response = self ._post ("dataset_collections" , payload , json = True )
535+ original_collection = self ._check_create_response (create_response )
536+ original_hdca_id = original_collection ["id" ]
537+
538+ # Verify the original sample sheet has columns metadata
539+ original_elements = original_collection ["elements" ]
540+ assert len (original_elements ) == 2
541+ assert original_elements [0 ]["columns" ] == [1 , "control" ]
542+ assert original_elements [1 ]["columns" ] == [2 , "treatment" ]
543+
544+ # Copy the collection using the new copy_collection method
545+ copy_response = self .dataset_collection_populator .copy_collection (
546+ history_id , original_hdca_id , copy_elements = True , wait = False
547+ )
548+ copied_collection = copy_response .json ()
549+
550+ # Fetch the full details of the copied collection
551+ copied_collection_details = self .dataset_populator .get_history_collection_details (
552+ history_id , content_id = copied_collection ["id" ]
553+ )
554+
555+ # Verify the copied collection has the same columns metadata
556+ copied_elements = copied_collection_details ["elements" ]
557+ assert len (copied_elements ) == 2 , f"Expected 2 elements, got { len (copied_elements )} "
558+
559+ # Check that columns metadata was preserved for each element
560+ self ._assert_has_keys (copied_elements [0 ], "columns" )
561+ assert copied_elements [0 ]["columns" ] == [
562+ 1 ,
563+ "control" ,
564+ ], f"Expected [1, 'control'], got { copied_elements [0 ]['columns' ]} "
565+ assert copied_elements [0 ]["element_identifier" ] == "sample1"
566+
567+ self ._assert_has_keys (copied_elements [1 ], "columns" )
568+ assert copied_elements [1 ]["columns" ] == [
569+ 2 ,
570+ "treatment" ,
571+ ], f"Expected [2, 'treatment'], got { copied_elements [1 ]['columns' ]} "
572+ assert copied_elements [1 ]["element_identifier" ] == "sample2"
573+
574+ # Verify column definitions are preserved
575+ assert copied_collection_details ["column_definitions" ] == original_collection ["column_definitions" ]
576+ assert copied_collection_details ["collection_type" ] == "sample_sheet"
577+
511578 def test_workbook_download (self ):
512579 xlsx_file = self .dataset_collection_populator .download_workbook (
513580 "sample_sheet" ,
0 commit comments