|
| 1 | +import pathlib |
| 2 | +import unittest |
| 3 | + |
| 4 | +from fastapi.testclient import TestClient |
| 5 | + |
| 6 | +from server_api.main import app as server_api_app |
| 7 | + |
| 8 | + |
| 9 | +SNEMI_ROOT = pathlib.Path("/Users/adamg/seg.bio/testing_data/snemi") |
| 10 | +TEST_INPUT_PATH = SNEMI_ROOT / "image" / "test-input.tif" |
| 11 | +TRAIN_LABELS_PATH = SNEMI_ROOT / "seg" / "train-labels.tif" |
| 12 | + |
| 13 | + |
| 14 | +@unittest.skipUnless(TEST_INPUT_PATH.exists(), "SNEMI fixture is not available") |
| 15 | +class CheckFilesRouteTests(unittest.TestCase): |
| 16 | + def setUp(self): |
| 17 | + self.client = TestClient(server_api_app) |
| 18 | + |
| 19 | + def test_check_files_marks_snemi_image_as_not_label(self): |
| 20 | + response = self.client.post( |
| 21 | + "/check_files", |
| 22 | + json={ |
| 23 | + "filePath": str(TEST_INPUT_PATH), |
| 24 | + "folderPath": str(TEST_INPUT_PATH.parent), |
| 25 | + "name": TEST_INPUT_PATH.name, |
| 26 | + }, |
| 27 | + ) |
| 28 | + |
| 29 | + self.assertEqual(response.status_code, 200) |
| 30 | + self.assertEqual(response.json(), {"label": False}) |
| 31 | + |
| 32 | + def test_check_files_marks_snemi_labels_as_label(self): |
| 33 | + response = self.client.post( |
| 34 | + "/check_files", |
| 35 | + json={ |
| 36 | + "filePath": str(TRAIN_LABELS_PATH), |
| 37 | + "folderPath": str(TRAIN_LABELS_PATH.parent), |
| 38 | + "name": TRAIN_LABELS_PATH.name, |
| 39 | + }, |
| 40 | + ) |
| 41 | + |
| 42 | + self.assertEqual(response.status_code, 200) |
| 43 | + self.assertEqual(response.json(), {"label": True}) |
| 44 | + |
| 45 | + def test_check_files_returns_error_payload_for_missing_path(self): |
| 46 | + missing_path = SNEMI_ROOT / "image" / "does-not-exist.tif" |
| 47 | + response = self.client.post( |
| 48 | + "/check_files", |
| 49 | + json={ |
| 50 | + "filePath": str(missing_path), |
| 51 | + "folderPath": str(missing_path.parent), |
| 52 | + "name": missing_path.name, |
| 53 | + }, |
| 54 | + ) |
| 55 | + |
| 56 | + self.assertEqual(response.status_code, 200) |
| 57 | + self.assertIn("error", response.json()) |
| 58 | + |
| 59 | + |
| 60 | +if __name__ == "__main__": |
| 61 | + unittest.main() |
0 commit comments