|
2 | 2 |
|
3 | 3 | from typing import Any |
4 | 4 |
|
5 | | -from annofabapi.models import TaskPhase |
| 5 | +from annofabapi.models import ProjectMemberRole, TaskPhase |
6 | 6 | from annofabapi.utils import ( |
| 7 | + can_put_annotation, |
7 | 8 | get_number_of_rejections, |
8 | 9 | get_task_history_index_skipped_acceptance, |
9 | 10 | get_task_history_index_skipped_inspection, |
@@ -614,3 +615,50 @@ def test_get_task_history_index_skipped_inspection_検査1回_教師付で提出 |
614 | 615 | actual = get_task_history_index_skipped_inspection(task_history_list) |
615 | 616 | expected: list[int] = [] |
616 | 617 | assert all([a == b for a, b in zip(actual, expected)]) # noqa: C419 |
| 618 | + |
| 619 | + |
| 620 | +class TestCanPutAnnotation: |
| 621 | + MY_ACCOUNT_ID = "12345678-abcd-1234-abcd-1234abcd5678" |
| 622 | + OTHER_ACCOUNT_ID = "87654321-dcba-4321-dcba-4321dcba8765" |
| 623 | + |
| 624 | + def test_can_put_annotation_project_member_role_none_no_history(self): |
| 625 | + """project_member_role=None, 履歴なしの場合""" |
| 626 | + task: dict[str, Any] = {"histories_by_phase": [], "account_id": None} |
| 627 | + actual = can_put_annotation(task, self.MY_ACCOUNT_ID, project_member_role=None) |
| 628 | + assert actual is True |
| 629 | + |
| 630 | + def test_can_put_annotation_project_member_role_owner_with_history_different_account(self): |
| 631 | + """project_member_role=OWNER, 履歴あり、異なるアカウントID""" |
| 632 | + task = { |
| 633 | + "histories_by_phase": [{"phase": "annotation", "phase_stage": 1, "worked": True, "account_id": self.OTHER_ACCOUNT_ID}], |
| 634 | + "account_id": self.OTHER_ACCOUNT_ID, |
| 635 | + } |
| 636 | + actual = can_put_annotation(task, self.MY_ACCOUNT_ID, project_member_role=ProjectMemberRole.OWNER) |
| 637 | + assert actual is False |
| 638 | + |
| 639 | + def test_can_put_annotation_project_member_role_owner_with_history_same_account(self): |
| 640 | + """project_member_role=OWNER, 同じアカウントID""" |
| 641 | + task = { |
| 642 | + "histories_by_phase": [{"phase": "annotation", "phase_stage": 1, "worked": True, "account_id": self.MY_ACCOUNT_ID}], |
| 643 | + "account_id": self.MY_ACCOUNT_ID, |
| 644 | + } |
| 645 | + actual = can_put_annotation(task, self.MY_ACCOUNT_ID, project_member_role=ProjectMemberRole.OWNER) |
| 646 | + assert actual is True |
| 647 | + |
| 648 | + def test_can_put_annotation_project_member_role_accepter_same_account(self): |
| 649 | + """project_member_role=ACCEPTER, 同じアカウントID""" |
| 650 | + task = { |
| 651 | + "histories_by_phase": [], |
| 652 | + "account_id": self.MY_ACCOUNT_ID, |
| 653 | + } |
| 654 | + actual = can_put_annotation(task, self.MY_ACCOUNT_ID, project_member_role=ProjectMemberRole.ACCEPTER) |
| 655 | + assert actual is True |
| 656 | + |
| 657 | + def test_can_put_annotation_project_member_role_worker_same_account(self): |
| 658 | + """project_member_role=WORKER, 同じアカウントID""" |
| 659 | + task = { |
| 660 | + "histories_by_phase": [], |
| 661 | + "account_id": self.MY_ACCOUNT_ID, |
| 662 | + } |
| 663 | + actual = can_put_annotation(task, self.MY_ACCOUNT_ID, project_member_role=ProjectMemberRole.WORKER) |
| 664 | + assert actual is True |
0 commit comments