@@ -933,3 +933,119 @@ def test_remove_items_from_collection_partial_success(
933
933
rel for rel in item .get ("relationships" , []) if rel .get ("type" ) == "collections"
934
934
]
935
935
assert len (collection_relationships ) == 0
936
+
937
+
938
+ @pytest .mark .dependency (depends = ["test_create_collections" ])
939
+ def test_copy_sample_and_add_to_collection (client , default_sample_dict , default_collection ):
940
+ original_sample = default_sample_dict .copy ()
941
+ original_sample ["item_id" ] = "original_for_copy_test"
942
+ original_sample ["name" ] = "Original sample"
943
+
944
+ response = client .post ("/new-sample/" , json = original_sample )
945
+ assert response .status_code == 201
946
+ assert response .json ["status" ] == "success"
947
+
948
+ collection_dict = default_collection .dict ().copy ()
949
+ collection_dict ["collection_id" ] = "test_copy_collection"
950
+ response = client .put ("/collections" , json = {"data" : collection_dict })
951
+ assert response .status_code == 201
952
+ assert response .json ["status" ] == "success"
953
+
954
+ copy_request = {
955
+ "item_id" : "copied_in_collection" ,
956
+ "type" : default_sample_dict ["type" ],
957
+ "collections" : [{"collection_id" : "test_copy_collection" }],
958
+ "copy_from_item_id" : "original_for_copy_test" ,
959
+ }
960
+ response = client .post ("/new-sample/" , json = copy_request )
961
+ assert response .status_code == 201
962
+ assert response .json ["status" ] == "success"
963
+
964
+ response = client .get ("/get-item-data/copied_in_collection" )
965
+ assert response .status_code == 200
966
+ item_data = response .json ["item_data" ]
967
+ assert item_data ["item_id" ] == "copied_in_collection"
968
+
969
+ response = client .get ("/collections/test_copy_collection" )
970
+ assert response .status_code == 200
971
+ child_items = response .json ["child_items" ]
972
+ assert any (item ["item_id" ] == "copied_in_collection" for item in child_items )
973
+ assert not any (item ["item_id" ] == "original_for_copy_test" for item in child_items )
974
+
975
+
976
+ @pytest .mark .dependency (depends = ["test_copy_sample_and_add_to_collection" ])
977
+ def test_copy_sample_from_collection_to_different_collection (
978
+ client , default_sample_dict , default_collection
979
+ ):
980
+ collection1_dict = default_collection .dict ().copy ()
981
+ collection1_dict ["collection_id" ] = "collection_1"
982
+ response = client .put ("/collections" , json = {"data" : collection1_dict })
983
+ assert response .status_code == 201
984
+
985
+ collection2_dict = default_collection .dict ().copy ()
986
+ collection2_dict ["collection_id" ] = "collection_2"
987
+ response = client .put ("/collections" , json = {"data" : collection2_dict })
988
+ assert response .status_code == 201
989
+
990
+ original_sample = default_sample_dict .copy ()
991
+ original_sample ["item_id" ] = "sample_in_collection1"
992
+ original_sample ["collections" ] = [{"collection_id" : "collection_1" }]
993
+
994
+ response = client .post ("/new-sample/" , json = original_sample )
995
+ assert response .status_code == 201
996
+ assert response .json ["status" ] == "success"
997
+
998
+ response = client .get ("/collections/collection_1" )
999
+ assert response .status_code == 200
1000
+ assert any (item ["item_id" ] == "sample_in_collection1" for item in response .json ["child_items" ])
1001
+
1002
+ copy_request = {
1003
+ "item_id" : "sample_in_collection2" ,
1004
+ "type" : default_sample_dict ["type" ],
1005
+ "collections" : [{"collection_id" : "collection_2" }],
1006
+ "copy_from_item_id" : "sample_in_collection1" ,
1007
+ }
1008
+ response = client .post ("/new-sample/" , json = copy_request )
1009
+ assert response .status_code == 201
1010
+ assert response .json ["status" ] == "success"
1011
+
1012
+ response = client .get ("/collections/collection_2" )
1013
+ assert response .status_code == 200
1014
+ assert any (item ["item_id" ] == "sample_in_collection2" for item in response .json ["child_items" ])
1015
+
1016
+ response = client .get ("/collections/collection_1" )
1017
+ assert response .status_code == 200
1018
+ child_items = response .json ["child_items" ]
1019
+ assert not any (item ["item_id" ] == "sample_in_collection2" for item in child_items )
1020
+ assert any (item ["item_id" ] == "sample_in_collection1" for item in child_items )
1021
+
1022
+
1023
+ @pytest .mark .dependency (depends = ["test_copy_sample_from_collection_to_different_collection" ])
1024
+ def test_copy_sample_without_copying_collections (client , default_sample_dict , default_collection ):
1025
+ collection_dict = default_collection .dict ().copy ()
1026
+ collection_dict ["collection_id" ] = "test_no_auto_copy_collection"
1027
+ response = client .put ("/collections" , json = {"data" : collection_dict })
1028
+ assert response .status_code == 201
1029
+
1030
+ original_sample = default_sample_dict .copy ()
1031
+ original_sample ["item_id" ] = "original_in_collection"
1032
+ original_sample ["collections" ] = [{"collection_id" : "test_no_auto_copy_collection" }]
1033
+
1034
+ response = client .post ("/new-sample/" , json = original_sample )
1035
+ assert response .status_code == 201
1036
+ assert response .json ["status" ] == "success"
1037
+
1038
+ copy_request = {
1039
+ "item_id" : "copy_without_collection" ,
1040
+ "type" : default_sample_dict ["type" ],
1041
+ "copy_from_item_id" : "original_in_collection" ,
1042
+ }
1043
+ response = client .post ("/new-sample/" , json = copy_request )
1044
+ assert response .status_code == 201
1045
+ assert response .json ["status" ] == "success"
1046
+
1047
+ response = client .get ("/collections/test_no_auto_copy_collection" )
1048
+ assert response .status_code == 200
1049
+ child_items = response .json ["child_items" ]
1050
+ assert not any (item ["item_id" ] == "copy_without_collection" for item in child_items )
1051
+ assert any (item ["item_id" ] == "original_in_collection" for item in child_items )
0 commit comments