|
| 1 | +from unittest import TestCase |
| 2 | +from unittest.mock import patch |
| 3 | + |
| 4 | +from src.superannotate import AppException |
| 5 | +from src.superannotate.lib.core.service_types import ServiceResponse |
| 6 | +from superannotate import SAClient |
| 7 | + |
| 8 | + |
| 9 | +sa = SAClient() |
| 10 | + |
| 11 | + |
| 12 | +class TestSetFolderStatus(TestCase): |
| 13 | + PROJECT_NAME = "test_set_folder_status" |
| 14 | + FOLDER_NAME = "test_folder" |
| 15 | + PROJECT_DESCRIPTION = "desc" |
| 16 | + PROJECT_TYPE = "Vector" |
| 17 | + FOLDER_STATUSES = ["NotStarted", "InProgress", "Completed", "OnHold"] |
| 18 | + |
| 19 | + @classmethod |
| 20 | + def setUpClass(cls, *args, **kwargs): |
| 21 | + cls.tearDownClass() |
| 22 | + cls._project = sa.create_project( |
| 23 | + cls.PROJECT_NAME, cls.PROJECT_DESCRIPTION, cls.PROJECT_TYPE |
| 24 | + ) |
| 25 | + sa.create_folder(cls.PROJECT_NAME, cls.FOLDER_NAME) |
| 26 | + folder = sa.get_folder_metadata( |
| 27 | + project=cls.PROJECT_NAME, folder_name=cls.FOLDER_NAME |
| 28 | + ) |
| 29 | + assert folder["status"] == "NotStarted" |
| 30 | + |
| 31 | + @classmethod |
| 32 | + def tearDownClass(cls) -> None: |
| 33 | + sa.delete_project(cls.PROJECT_NAME) |
| 34 | + |
| 35 | + def test_set_folder_status(self): |
| 36 | + with self.assertLogs("sa", level="INFO") as cm: |
| 37 | + for index, status in enumerate( |
| 38 | + self.FOLDER_STATUSES |
| 39 | + ): |
| 40 | + sa.set_folder_status( |
| 41 | + project=self.PROJECT_NAME, folder=self.FOLDER_NAME, status=status |
| 42 | + ) |
| 43 | + folder = sa.get_folder_metadata( |
| 44 | + project=self.PROJECT_NAME, folder_name=self.FOLDER_NAME |
| 45 | + ) |
| 46 | + assert ( |
| 47 | + f"INFO:sa:Successfully updated {self.PROJECT_NAME}/{self.FOLDER_NAME} status to {status}" |
| 48 | + == cm.output[index] |
| 49 | + ) |
| 50 | + self.assertEqual(status, folder["status"]) |
| 51 | + self.assertEqual(len(cm.output), len(self.FOLDER_STATUSES)) |
| 52 | + |
| 53 | + @patch("lib.infrastructure.services.folder.FolderService.update") |
| 54 | + def test_set_folder_status_fail(self, update_function): |
| 55 | + update_function.return_value = ServiceResponse(_error="ERROR") |
| 56 | + with self.assertRaisesRegexp( |
| 57 | + AppException, |
| 58 | + f"Failed to change {self.PROJECT_NAME}/{self.FOLDER_NAME} status.", |
| 59 | + ): |
| 60 | + sa.set_folder_status( |
| 61 | + project=self.PROJECT_NAME, folder=self.FOLDER_NAME, status="Completed" |
| 62 | + ) |
| 63 | + |
| 64 | + def test_set_folder_status_via_invalid_status(self): |
| 65 | + with self.assertRaisesRegexp( |
| 66 | + AppException, |
| 67 | + "Available values are 'NotStarted', 'InProgress', 'Completed', 'OnHold'.", |
| 68 | + ): |
| 69 | + sa.set_folder_status( |
| 70 | + project=self.PROJECT_NAME, |
| 71 | + folder=self.FOLDER_NAME, |
| 72 | + status="InvalidStatus", |
| 73 | + ) |
| 74 | + |
| 75 | + def test_set_folder_status_via_invalid_project(self): |
| 76 | + with self.assertRaisesRegexp( |
| 77 | + AppException, |
| 78 | + "Project not found.", |
| 79 | + ): |
| 80 | + sa.set_folder_status( |
| 81 | + project="Invalid Name", folder=self.FOLDER_NAME, status="Completed" |
| 82 | + ) |
| 83 | + |
| 84 | + def test_set_folder_status_via_invalid_folder(self): |
| 85 | + with self.assertRaisesRegexp( |
| 86 | + AppException, |
| 87 | + "Folder not found.", |
| 88 | + ): |
| 89 | + sa.set_folder_status( |
| 90 | + project=self.PROJECT_NAME, folder="Invalid Name", status="Completed" |
| 91 | + ) |
0 commit comments