| @@ 938-990 (lines=53) @@ | ||
| 935 | workspace = res.json_body |
|
| 936 | assert workspace['is_deleted'] is True |
|
| 937 | ||
| 938 | def test_api__undelete_workspace__err_400__manager(self) -> None: |
|
| 939 | """ |
|
| 940 | Test delete workspace as global manager without having any role in the |
|
| 941 | workspace |
|
| 942 | """ |
|
| 943 | self.testapp.authorization = ( |
|
| 944 | 'Basic', |
|
| 945 | ( |
|
| 946 | '[email protected]', |
|
| 947 | '[email protected]' |
|
| 948 | ) |
|
| 949 | ) |
|
| 950 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 951 | admin = dbsession.query(models.User) \ |
|
| 952 | .filter(models.User.email == '[email protected]') \ |
|
| 953 | .one() |
|
| 954 | uapi = UserApi( |
|
| 955 | current_user=admin, |
|
| 956 | session=dbsession, |
|
| 957 | config=self.app_config, |
|
| 958 | ) |
|
| 959 | user = uapi.create_user('[email protected]', password='[email protected]', |
|
| 960 | do_save=True, do_notify=False) # nopep8 |
|
| 961 | workspace_api = WorkspaceApi( |
|
| 962 | current_user=admin, |
|
| 963 | session=dbsession, |
|
| 964 | config=self.app_config, |
|
| 965 | show_deleted=True, |
|
| 966 | ) |
|
| 967 | workspace = workspace_api.create_workspace('test', save_now=True) # nopep8 |
|
| 968 | workspace_api.delete(workspace, flush=True) |
|
| 969 | rapi = RoleApi( |
|
| 970 | current_user=admin, |
|
| 971 | session=dbsession, |
|
| 972 | config=self.app_config, |
|
| 973 | ) |
|
| 974 | transaction.commit() |
|
| 975 | workspace_id = int(workspace.workspace_id) |
|
| 976 | self.testapp.authorization = ( |
|
| 977 | 'Basic', |
|
| 978 | ( |
|
| 979 | '[email protected]', |
|
| 980 | '[email protected]' |
|
| 981 | ) |
|
| 982 | ) |
|
| 983 | # delete |
|
| 984 | res = self.testapp.put( |
|
| 985 | '/api/v2/workspaces/{}/trashed/restore'.format(workspace_id), |
|
| 986 | status=400 |
|
| 987 | ) |
|
| 988 | assert isinstance(res.json, dict) |
|
| 989 | assert 'code' in res.json.keys() |
|
| 990 | assert res.json_body['code'] == error.WORKSPACE_NOT_FOUND |
|
| 991 | ||
| 992 | def test_api__get_workspace__err_400__unallowed_user(self) -> None: |
|
| 993 | """ |
|
| @@ 614-666 (lines=53) @@ | ||
| 611 | workspace = res.json_body |
|
| 612 | assert workspace['is_deleted'] is False |
|
| 613 | ||
| 614 | def test_api__delete_workspace__err_400__manager(self) -> None: |
|
| 615 | """ |
|
| 616 | Test delete workspace as global manager without having any role in the |
|
| 617 | workspace |
|
| 618 | """ |
|
| 619 | self.testapp.authorization = ( |
|
| 620 | 'Basic', |
|
| 621 | ( |
|
| 622 | '[email protected]', |
|
| 623 | '[email protected]' |
|
| 624 | ) |
|
| 625 | ) |
|
| 626 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 627 | admin = dbsession.query(models.User) \ |
|
| 628 | .filter(models.User.email == '[email protected]') \ |
|
| 629 | .one() |
|
| 630 | uapi = UserApi( |
|
| 631 | current_user=admin, |
|
| 632 | session=dbsession, |
|
| 633 | config=self.app_config, |
|
| 634 | ) |
|
| 635 | user = uapi.create_user('[email protected]', password='[email protected]', |
|
| 636 | do_save=True, do_notify=False) # nopep8 |
|
| 637 | workspace_api = WorkspaceApi( |
|
| 638 | current_user=admin, |
|
| 639 | session=dbsession, |
|
| 640 | config=self.app_config, |
|
| 641 | show_deleted=True, |
|
| 642 | ) |
|
| 643 | workspace = workspace_api.create_workspace('test', |
|
| 644 | save_now=True) # nopep8 |
|
| 645 | rapi = RoleApi( |
|
| 646 | current_user=admin, |
|
| 647 | session=dbsession, |
|
| 648 | config=self.app_config, |
|
| 649 | ) |
|
| 650 | transaction.commit() |
|
| 651 | workspace_id = int(workspace.workspace_id) |
|
| 652 | self.testapp.authorization = ( |
|
| 653 | 'Basic', |
|
| 654 | ( |
|
| 655 | '[email protected]', |
|
| 656 | '[email protected]' |
|
| 657 | ) |
|
| 658 | ) |
|
| 659 | # delete |
|
| 660 | res = self.testapp.put( |
|
| 661 | '/api/v2/workspaces/{}/trashed'.format(workspace_id), |
|
| 662 | status=400 |
|
| 663 | ) |
|
| 664 | assert isinstance(res.json, dict) |
|
| 665 | assert 'code' in res.json.keys() |
|
| 666 | assert res.json_body['code'] == error.WORKSPACE_NOT_FOUND |
|
| 667 | ||
| 668 | def test_api__undelete_workspace__ok_200__admin(self) -> None: |
|
| 669 | """ |
|