1+ import json
12import os
3+ import tempfile
4+ from os .path import join
25from pathlib import Path
36
47from src .superannotate import SAClient
@@ -11,13 +14,14 @@ class TestMoveItems(BaseTestCase):
1114 PROJECT_NAME = "TestMoveItemsVector"
1215 PROJECT_DESCRIPTION = "TestCopyItemsVector"
1316 PROJECT_TYPE = "Vector"
14- IMAGE_NAME = "test_image "
15- IMAGE_NAME_2 = "test_image_2 "
17+ IMAGE_NAME = "example_image_1.jpg "
18+ IMAGE_NAME_2 = "example_image_2.jpg "
1619 FOLDER_1 = "folder_1"
1720 FOLDER_2 = "folder_2"
1821 CSV_PATH = "data_set/attach_urls.csv"
22+ TEST_FOLDER_PATH = "data_set/sample_project_vector"
1923
20- Attachment = [
24+ ATTACHMENT = [
2125 {
2226 "url" : "https://drive.google.com/uc?export=download&id=1vwfCpTzcjxoEA4hhDxqapPOVvLVeS7ZS" ,
2327 "name" : IMAGE_NAME ,
@@ -28,6 +32,10 @@ class TestMoveItems(BaseTestCase):
2832 },
2933 ]
3034
35+ @property
36+ def folder_path (self ):
37+ return os .path .join (Path (__file__ ).parent .parent .parent , self .TEST_FOLDER_PATH )
38+
3139 @property
3240 def scv_path (self ):
3341 return os .path .join (Path (__file__ ).parent .parent .parent , self .CSV_PATH )
@@ -46,22 +54,37 @@ def test_move_items_from_folder(self):
4654 sa .create_folder (self .PROJECT_NAME , self .FOLDER_1 )
4755 sa .create_folder (self .PROJECT_NAME , self .FOLDER_2 )
4856 uploaded , _ , _ = sa .attach_items (
49- f"{ self .PROJECT_NAME } /{ self .FOLDER_1 } " , self .scv_path
57+ f"{ self .PROJECT_NAME } /{ self .FOLDER_1 } " , self .ATTACHMENT
5058 )
51- assert len (uploaded ) == 7
59+ annotation_path = join (self .folder_path , f"{ self .IMAGE_NAME } ___objects.json" )
60+ sa .upload_image_annotations (
61+ f"{ self .PROJECT_NAME } /{ self .FOLDER_1 } " , self .IMAGE_NAME , annotation_path
62+ )
63+
64+ assert len (uploaded ) == 2
5265 skipped_items = sa .move_items (
5366 f"{ self .PROJECT_NAME } /{ self .FOLDER_1 } " ,
5467 f"{ self .PROJECT_NAME } /{ self .FOLDER_2 } " ,
5568 )
5669 assert len (skipped_items ) == 0
57- assert len (sa .search_items (f"{ self .PROJECT_NAME } /{ self .FOLDER_2 } " )) == 7
70+ assert len (sa .search_items (f"{ self .PROJECT_NAME } /{ self .FOLDER_2 } " )) == 2
5871 assert len (sa .search_items (f"{ self .PROJECT_NAME } /{ self .FOLDER_1 } " )) == 0
72+ with tempfile .TemporaryDirectory () as tmp_dir :
73+ sa .download_image_annotations (
74+ f"{ self .PROJECT_NAME } /{ self .FOLDER_2 } " , self .IMAGE_NAME , tmp_dir
75+ )
76+ origin_annotation = json .load (open (annotation_path ))
77+ annotation = json .load (open (join (tmp_dir , f"{ self .IMAGE_NAME } .json" )))
78+ self .assertEqual (
79+ len ([i ["attributes" ] for i in annotation ["instances" ]]),
80+ len ([i ["attributes" ] for i in origin_annotation ["instances" ]]),
81+ )
5982
6083 def test_move_items_from_folder_with_replace (self ):
6184 sa .create_folder (self .PROJECT_NAME , self .FOLDER_1 )
6285 sa .create_folder (self .PROJECT_NAME , self .FOLDER_2 )
6386 uploaded , _ , _ = sa .attach_items (
64- f"{ self .PROJECT_NAME } /{ self .FOLDER_1 } " , self .Attachment
87+ f"{ self .PROJECT_NAME } /{ self .FOLDER_1 } " , self .ATTACHMENT
6588 )
6689 assert len (uploaded ) == 2
6790 sa .set_approval_statuses (
@@ -76,7 +99,7 @@ def test_move_items_from_folder_with_replace(self):
7699 )
77100
78101 uploaded_2 , _ , _ = sa .attach_items (
79- f"{ self .PROJECT_NAME } /{ self .FOLDER_2 } " , self .Attachment
102+ f"{ self .PROJECT_NAME } /{ self .FOLDER_2 } " , self .ATTACHMENT
80103 )
81104 assert len (uploaded_2 ) == 2
82105 folder_2_items = sa .search_items (f"{ self .PROJECT_NAME } /{ self .FOLDER_2 } " )
@@ -102,7 +125,7 @@ def test_move_items_from_folder_with_replace_annotations_only(self):
102125 sa .create_folder (self .PROJECT_NAME , self .FOLDER_1 )
103126 sa .create_folder (self .PROJECT_NAME , self .FOLDER_2 )
104127 uploaded , _ , _ = sa .attach_items (
105- f"{ self .PROJECT_NAME } /{ self .FOLDER_1 } " , self .Attachment
128+ f"{ self .PROJECT_NAME } /{ self .FOLDER_1 } " , self .ATTACHMENT
106129 )
107130 assert len (uploaded ) == 2
108131 sa .set_approval_statuses (
@@ -115,9 +138,13 @@ def test_move_items_from_folder_with_replace_annotations_only(self):
115138 "Completed" ,
116139 items = [self .IMAGE_NAME , self .IMAGE_NAME_2 ],
117140 )
141+ annotation_path = join (self .folder_path , f"{ self .IMAGE_NAME } ___objects.json" )
142+ sa .upload_image_annotations (
143+ f"{ self .PROJECT_NAME } /{ self .FOLDER_1 } " , self .IMAGE_NAME , annotation_path
144+ )
118145
119146 uploaded_2 , _ , _ = sa .attach_items (
120- f"{ self .PROJECT_NAME } /{ self .FOLDER_2 } " , self .Attachment
147+ f"{ self .PROJECT_NAME } /{ self .FOLDER_2 } " , self .ATTACHMENT
121148 )
122149 assert len (uploaded_2 ) == 2
123150 folder_2_items = sa .search_items (f"{ self .PROJECT_NAME } /{ self .FOLDER_2 } " )
@@ -138,17 +165,27 @@ def test_move_items_from_folder_with_replace_annotations_only(self):
138165 folder_2_items = sa .search_items (f"{ self .PROJECT_NAME } /{ self .FOLDER_2 } " )
139166 assert folder_2_items [0 ]["annotation_status" ] == "NotStarted"
140167 assert not folder_2_items [0 ]["approval_status" ]
168+ with tempfile .TemporaryDirectory () as tmp_dir :
169+ sa .download_image_annotations (
170+ f"{ self .PROJECT_NAME } /{ self .FOLDER_2 } " , self .IMAGE_NAME , tmp_dir
171+ )
172+ origin_annotation = json .load (open (annotation_path ))
173+ annotation = json .load (open (join (tmp_dir , f"{ self .IMAGE_NAME } .json" )))
174+ self .assertEqual (
175+ len ([i ["attributes" ] for i in annotation ["instances" ]]),
176+ len ([i ["attributes" ] for i in origin_annotation ["instances" ]]),
177+ )
141178
142179 def test_move_items_from_folder_with_skip (self ):
143180 sa .create_folder (self .PROJECT_NAME , self .FOLDER_1 )
144181 sa .create_folder (self .PROJECT_NAME , self .FOLDER_2 )
145182 uploaded , _ , _ = sa .attach_items (
146- f"{ self .PROJECT_NAME } /{ self .FOLDER_1 } " , self .Attachment
183+ f"{ self .PROJECT_NAME } /{ self .FOLDER_1 } " , self .ATTACHMENT
147184 )
148185 assert len (uploaded ) == 2
149186
150187 uploaded_2 , _ , _ = sa .attach_items (
151- f"{ self .PROJECT_NAME } /{ self .FOLDER_2 } " , self .Attachment
188+ f"{ self .PROJECT_NAME } /{ self .FOLDER_2 } " , self .ATTACHMENT
152189 )
153190 assert len (uploaded_2 ) == 2
154191
0 commit comments