Skip to content

Commit ad9738f

Browse files
author
Leandro Rosemberg
committed
Test validating the annotation error
1 parent 6582e32 commit ad9738f

File tree

1 file changed

+56
-6
lines changed

1 file changed

+56
-6
lines changed

tests/test_project.py

Lines changed: 56 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
from roboflow import API_URL
44
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
77

88

99
class TestProject(RoboflowTest):
@@ -43,14 +43,13 @@ def test_check_valid_image_with_unaccepted_formats(self):
4343
for image in images_to_test:
4444
self.assertFalse(self.project.check_valid_image(f"tests/images/{image}"))
4545

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):
4747
responses.add(
4848
responses.POST,
4949
f"{API_URL}/dataset/{PROJECT_NAME}/upload?api_key={ROBOFLOW_API_KEY}" f"&batch={DEFAULT_BATCH_NAME}",
5050
json={
51-
"message": "Image was already annotated.",
51+
"message": "Invalid Image",
5252
"type": "InvalidImageException",
53-
"hint": "This image was already annotated; to overwrite the annotation, pass overwrite=true...",
5453
},
5554
status=200,
5655
)
@@ -61,4 +60,55 @@ def test_upload_image_that_already_is_annotated_raises_upload_image_error(self):
6160
annotation_path="tests/annotations/valid_annotation.json",
6261
)
6362

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

Comments
 (0)