1+ import io
12import os
23from os .path import dirname
34
78sa = SAClient ()
89
910
10- class TestDuplicateImage (BaseTestCase ):
11- PROJECT_NAME = "duplicate_image "
11+ class TestSingleImageUpload (BaseTestCase ):
12+ PROJECT_NAME = "single_image_upload "
1213 PROJECT_DESCRIPTION = "Desc"
1314 PROJECT_TYPE = "Vector"
1415 TEST_FOLDER_PTH = "data_set"
@@ -25,6 +26,41 @@ def classes_path(self):
2526 )
2627
2728 def test_single_image_upload (self ):
29+ sa .upload_image_to_project (
30+ self .PROJECT_NAME ,
31+ self .folder_path + "/example_image_1.jpg" ,
32+ annotation_status = "InProgress" ,
33+ )
34+ assert len (sa .search_items (self .PROJECT_NAME )) == 1
35+
36+ with open (self .folder_path + "/example_image_1.jpg" , "rb" ) as f :
37+ img = io .BytesIO (f .read ())
38+
39+ sa .upload_image_to_project (
40+ self .PROJECT_NAME , img , image_name = "rr.jpg" , annotation_status = "InProgress"
41+ )
42+
43+ assert len (sa .search_items (self .PROJECT_NAME )) == 2
44+
45+
46+ class TestMultipleImageUpload (BaseTestCase ):
47+ PROJECT_NAME = "test_multiple_image_upload"
48+ PROJECT_DESCRIPTION = "Desc"
49+ PROJECT_TYPE = "Vector"
50+ TEST_FOLDER_PTH = "data_set"
51+ TEST_FOLDER_PATH = "data_set/sample_project_vector"
52+
53+ @property
54+ def folder_path (self ):
55+ return os .path .join (dirname (dirname (__file__ )), self .TEST_FOLDER_PATH )
56+
57+ @property
58+ def classes_path (self ):
59+ return os .path .join (
60+ dirname (dirname (__file__ )), self .TEST_FOLDER_PATH , "classes/classes.json"
61+ )
62+
63+ def test_multiple_image_upload (self ):
2864 (uploaded , could_not_upload , existing_images ,) = sa .upload_images_to_project (
2965 self .PROJECT_NAME ,
3066 [
@@ -59,3 +95,19 @@ def test_single_image_upload(self):
5995 self .assertEqual (len (uploaded ), 0 )
6096 self .assertEqual (len (could_not_upload ), 1 )
6197 self .assertEqual (len (existing_images ), 0 )
98+
99+ def test_multiple_image_upload_with_duplicates (self ):
100+ (uploaded , could_not_upload , existing_images ,) = sa .upload_images_to_project (
101+ self .PROJECT_NAME ,
102+ [
103+ f"{ self .folder_path } /example_image_1.jpg" ,
104+ f"{ self .folder_path } /example_image_1.jpg" ,
105+ f"{ self .folder_path } /example_image_1.jpg" ,
106+ f"{ self .folder_path } /example_image_3.jpg" ,
107+ f"{ self .folder_path } /example_image_4.jpg" ,
108+ ],
109+ annotation_status = "InProgress" ,
110+ )
111+ self .assertEqual (len (uploaded ), 3 )
112+ self .assertEqual (len (could_not_upload ), 0 )
113+ self .assertEqual (len (existing_images ), 2 )
0 commit comments