2
2
3
3
from roboflow import API_URL
4
4
from roboflow .config import DEFAULT_BATCH_NAME
5
- from roboflow .core .exceptions import UploadImageError
6
- from tests import PROJECT_NAME , ROBOFLOW_API_KEY , RoboflowTest
5
+ from roboflow .core .exceptions import UploadImageError , AnnotationUploadError
6
+ from tests import RoboflowTest , PROJECT_NAME , ROBOFLOW_API_KEY
7
7
8
8
9
9
class TestProject (RoboflowTest ):
@@ -43,14 +43,13 @@ def test_check_valid_image_with_unaccepted_formats(self):
43
43
for image in images_to_test :
44
44
self .assertFalse (self .project .check_valid_image (f"tests/images/{ image } " ))
45
45
46
- def test_upload_image_that_already_is_annotated_raises_upload_image_error (self ):
46
+ def test_upload_raises_upload_image_error_response_200 (self ):
47
47
responses .add (
48
48
responses .POST ,
49
49
f"{ API_URL } /dataset/{ PROJECT_NAME } /upload?api_key={ ROBOFLOW_API_KEY } " f"&batch={ DEFAULT_BATCH_NAME } " ,
50
50
json = {
51
- "message" : "Image was already annotated. " ,
51
+ "message" : "Invalid Image " ,
52
52
"type" : "InvalidImageException" ,
53
- "hint" : "This image was already annotated; to overwrite the annotation, pass overwrite=true..." ,
54
53
},
55
54
status = 200 ,
56
55
)
@@ -61,4 +60,55 @@ def test_upload_image_that_already_is_annotated_raises_upload_image_error(self):
61
60
annotation_path = "tests/annotations/valid_annotation.json" ,
62
61
)
63
62
64
- self .assertEqual (str (error .exception ), "Error uploading image: Image was already annotated." )
63
+ self .assertEquals (str (error .exception ), "Error uploading image: Invalid Image" )
64
+
65
+ def test_upload_raises_upload_image_error_response_400 (self ):
66
+ responses .add (
67
+ responses .POST ,
68
+ f"{ API_URL } /dataset/{ PROJECT_NAME } /upload?api_key={ ROBOFLOW_API_KEY } " f"&batch={ DEFAULT_BATCH_NAME } " ,
69
+ json = {
70
+ "message" : "Invalid Image" ,
71
+ "type" : "InvalidImageException" ,
72
+ },
73
+ status = 400 ,
74
+ )
75
+
76
+ with self .assertRaises (UploadImageError ) as error :
77
+ self .project .upload (
78
+ "tests/images/rabbit.JPG" ,
79
+ annotation_path = "tests/annotations/valid_annotation.json" ,
80
+ )
81
+
82
+ self .assertEquals (str (error .exception ), "Error uploading image: Invalid Image" )
83
+
84
+ def test_upload_raises_upload_annotation_error (self ):
85
+ image_id = "hbALkCFdNr9rssgOUXug"
86
+ image_name = "invalid_annotation.json"
87
+
88
+ # Image upload
89
+ responses .add (
90
+ responses .POST ,
91
+ f"{ API_URL } /dataset/{ PROJECT_NAME } /upload?api_key={ ROBOFLOW_API_KEY } " f"&batch={ DEFAULT_BATCH_NAME } " ,
92
+ json = {"success" : True , "id" : image_id },
93
+ status = 200 ,
94
+ )
95
+
96
+ # Annotation
97
+ responses .add (
98
+ responses .POST ,
99
+ f"{ API_URL } /dataset/{ PROJECT_NAME } /annotate/{ image_id } ?api_key={ ROBOFLOW_API_KEY } " f"&name={ image_name } " ,
100
+ json = {
101
+ "message" : "Image was already annotated." ,
102
+ "type" : "InvalidImageException" ,
103
+ "hint" : "This image was already annotated; to overwrite the annotation, pass overwrite=true..." ,
104
+ },
105
+ status = 400 ,
106
+ )
107
+
108
+ with self .assertRaises (AnnotationUploadError ) as error :
109
+ self .project .upload (
110
+ "tests/images/rabbit.JPG" ,
111
+ annotation_path = f"tests/annotations/{ image_name } " ,
112
+ )
113
+
114
+ self .assertEquals (str (error .exception ), "Error uploading annotation: Image was already annotated." )
0 commit comments