|
1 | 1 | import requests
|
2 | 2 | import responses
|
| 3 | +from responses.matchers import json_params_matcher |
3 | 4 |
|
4 | 5 | from roboflow import API_URL
|
5 | 6 | from roboflow.adapters.rfapi import AnnotationSaveError, ImageUploadError
|
@@ -144,3 +145,81 @@ def test_image_invalid_json_response(self):
|
144 | 145 | self.project.image(image_id)
|
145 | 146 |
|
146 | 147 | self.assertIn("Expecting value", str(context.exception))
|
| 148 | + |
| 149 | + def test_create_annotation_job_success(self): |
| 150 | + job_name = "Test Job" |
| 151 | + batch_id = "test-batch-123" |
| 152 | + num_images = 10 |
| 153 | + labeler_email = "[email protected]" |
| 154 | + reviewer_email = "[email protected]" |
| 155 | + |
| 156 | + expected_response = { |
| 157 | + "success": True, |
| 158 | + "job": { |
| 159 | + "id": "job-123", |
| 160 | + "name": job_name, |
| 161 | + "batch": batch_id, |
| 162 | + "num_images": num_images, |
| 163 | + "labeler": labeler_email, |
| 164 | + "reviewer": reviewer_email, |
| 165 | + "status": "created", |
| 166 | + "created": 1616161616, |
| 167 | + }, |
| 168 | + } |
| 169 | + |
| 170 | + expected_url = f"{API_URL}/{WORKSPACE_NAME}/{PROJECT_NAME}/jobs?api_key={ROBOFLOW_API_KEY}" |
| 171 | + |
| 172 | + responses.add( |
| 173 | + responses.POST, |
| 174 | + expected_url, |
| 175 | + json=expected_response, |
| 176 | + status=200, |
| 177 | + match=[ |
| 178 | + json_params_matcher( |
| 179 | + { |
| 180 | + "name": job_name, |
| 181 | + "batch": batch_id, |
| 182 | + "num_images": num_images, |
| 183 | + "labelerEmail": labeler_email, |
| 184 | + "reviewerEmail": reviewer_email, |
| 185 | + } |
| 186 | + ) |
| 187 | + ], |
| 188 | + ) |
| 189 | + |
| 190 | + result = self.project.create_annotation_job( |
| 191 | + name=job_name, |
| 192 | + batch_id=batch_id, |
| 193 | + num_images=num_images, |
| 194 | + labeler_email=labeler_email, |
| 195 | + reviewer_email=reviewer_email, |
| 196 | + ) |
| 197 | + |
| 198 | + self.assertEqual(result, expected_response) |
| 199 | + self.assertTrue(result["success"]) |
| 200 | + self.assertEqual(result["job"]["id"], "job-123") |
| 201 | + self.assertEqual(result["job"]["name"], job_name) |
| 202 | + |
| 203 | + def test_create_annotation_job_error(self): |
| 204 | + job_name = "Test Job" |
| 205 | + batch_id = "invalid-batch" |
| 206 | + num_images = 10 |
| 207 | + labeler_email = "[email protected]" |
| 208 | + reviewer_email = "[email protected]" |
| 209 | + |
| 210 | + error_response = {"error": "Batch not found"} |
| 211 | + |
| 212 | + expected_url = f"{API_URL}/{WORKSPACE_NAME}/{PROJECT_NAME}/jobs?api_key={ROBOFLOW_API_KEY}" |
| 213 | + |
| 214 | + responses.add(responses.POST, expected_url, json=error_response, status=404) |
| 215 | + |
| 216 | + with self.assertRaises(RuntimeError) as context: |
| 217 | + self.project.create_annotation_job( |
| 218 | + name=job_name, |
| 219 | + batch_id=batch_id, |
| 220 | + num_images=num_images, |
| 221 | + labeler_email=labeler_email, |
| 222 | + reviewer_email=reviewer_email, |
| 223 | + ) |
| 224 | + |
| 225 | + self.assertEqual(str(context.exception), "Batch not found") |
0 commit comments