|
| 1 | +from pathlib import Path |
| 2 | + |
1 | 3 | import pytest |
2 | 4 | from fastapi.testclient import TestClient |
3 | 5 |
|
|
22 | 24 | wait_for_task_completion, |
23 | 25 | ) |
24 | 26 |
|
| 27 | +TEST_ASSETS_DIR = Path("tests/integration/assets") |
| 28 | +MULTI_TEXT_FILE_PATH = TEST_ASSETS_DIR / "multi_text_file.json" |
| 29 | + |
25 | 30 |
|
26 | 31 | @pytest.fixture(scope="module", autouse=True) |
27 | 32 | def setup(request: pytest.FixtureRequest, cleanup_cms: bool): |
@@ -242,3 +247,39 @@ def test_process_bulk(client: TestClient, config: Config, test_model_service_ip: |
242 | 247 | assert annotation["label_name"] == "Loss Of Kidney Function" |
243 | 248 |
|
244 | 249 | verify_results_match_api_info(client, task, res) |
| 250 | + |
| 251 | + |
| 252 | +def test_process_bulk_file(client: TestClient, config: Config, test_model_service_ip: str): |
| 253 | + with open(MULTI_TEXT_FILE_PATH, "rb") as f: |
| 254 | + response = client.post( |
| 255 | + f"/models/{test_model_service_ip}/process_bulk_file", |
| 256 | + files=[("multi_text_file", f)], |
| 257 | + ) |
| 258 | + response_json = validate_api_response(response, expected_status_code=200, return_json=True) |
| 259 | + |
| 260 | + tm: TaskManager = config.task_manager |
| 261 | + verify_task_submitted_successfully(response_json["uuid"], tm) |
| 262 | + |
| 263 | + task = wait_for_task_completion(response_json["uuid"], tm, expected_status=Status.SUCCEEDED) |
| 264 | + |
| 265 | + key = f"{task.uuid}_{MULTI_TEXT_FILE_PATH.name}" |
| 266 | + with open(MULTI_TEXT_FILE_PATH, "rb") as f: |
| 267 | + expected_payload = f.read() |
| 268 | + verify_task_payload_in_object_store(key, expected_payload, config.task_object_store_manager) |
| 269 | + |
| 270 | + verify_queue_is_empty(config.queue_manager) |
| 271 | + |
| 272 | + res, parsed = download_result_object(task.result, config.results_object_store_manager) |
| 273 | + |
| 274 | + assert len(parsed) == 2 |
| 275 | + |
| 276 | + for doc in parsed: |
| 277 | + assert "text" in doc |
| 278 | + assert "annotations" in doc |
| 279 | + assert len(doc["annotations"]) == 1 |
| 280 | + |
| 281 | + annotation = doc["annotations"][0] |
| 282 | + verify_annotation_contains_keys(annotation, ANNOTATION_FIELDS_JSON) |
| 283 | + assert annotation["label_name"] == "Loss Of Kidney Function" |
| 284 | + |
| 285 | + verify_results_match_api_info(client, task, res) |
0 commit comments