| @@ 789-862 (lines=74) @@ | ||
| 786 | assert res.json_body[1]['content_id'] == main_folder.content_id |
|
| 787 | assert res.json_body[1]['read_by_user'] is True |
|
| 788 | ||
| 789 | class TestAccountEnableWorkspaceNotification(FunctionalTest): |
|
| 790 | """ |
|
| 791 | Tests for /api/v2/users/{user_id}/workspaces/{workspace_id}/notifications/activate |
|
| 792 | """ |
|
| 793 | def test_api_enable_account_workspace_notification__ok__200__user_nominal(self): |
|
| 794 | # init DB |
|
| 795 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 796 | admin = dbsession.query(models.User) \ |
|
| 797 | .filter(models.User.email == '[email protected]') \ |
|
| 798 | .one() |
|
| 799 | workspace_api = WorkspaceApi( |
|
| 800 | current_user=admin, |
|
| 801 | session=dbsession, |
|
| 802 | config=self.app_config |
|
| 803 | ||
| 804 | ) |
|
| 805 | workspace = WorkspaceApi( |
|
| 806 | current_user=admin, |
|
| 807 | session=dbsession, |
|
| 808 | config=self.app_config, |
|
| 809 | ).create_workspace( |
|
| 810 | 'test workspace', |
|
| 811 | save_now=True |
|
| 812 | ) |
|
| 813 | uapi = UserApi( |
|
| 814 | current_user=admin, |
|
| 815 | session=dbsession, |
|
| 816 | config=self.app_config, |
|
| 817 | ) |
|
| 818 | gapi = GroupApi( |
|
| 819 | current_user=admin, |
|
| 820 | session=dbsession, |
|
| 821 | config=self.app_config, |
|
| 822 | ) |
|
| 823 | groups = [gapi.get_one_with_name('users')] |
|
| 824 | test_user = uapi.create_user( |
|
| 825 | email='[email protected]', |
|
| 826 | password='pass', |
|
| 827 | name='bob', |
|
| 828 | groups=groups, |
|
| 829 | timezone='Europe/Paris', |
|
| 830 | lang='fr', |
|
| 831 | do_save=True, |
|
| 832 | do_notify=False, |
|
| 833 | ) |
|
| 834 | rapi = RoleApi( |
|
| 835 | current_user=admin, |
|
| 836 | session=dbsession, |
|
| 837 | config=self.app_config, |
|
| 838 | ) |
|
| 839 | rapi.create_one(test_user, workspace, UserRoleInWorkspace.READER, with_notif=False) # nopep8 |
|
| 840 | transaction.commit() |
|
| 841 | role = rapi.get_one(test_user.user_id, workspace.workspace_id) |
|
| 842 | assert role.do_notify is False |
|
| 843 | self.testapp.authorization = ( |
|
| 844 | 'Basic', |
|
| 845 | ( |
|
| 846 | '[email protected]', |
|
| 847 | 'pass', |
|
| 848 | ) |
|
| 849 | ) |
|
| 850 | self.testapp.put_json('/api/v2/users/{user_id}/workspaces/{workspace_id}/notifications/activate'.format( # nopep8 |
|
| 851 | user_id=test_user.user_id, |
|
| 852 | workspace_id=workspace.workspace_id |
|
| 853 | ), status=204) |
|
| 854 | ||
| 855 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 856 | rapi = RoleApi( |
|
| 857 | current_user=admin, |
|
| 858 | session=dbsession, |
|
| 859 | config=self.app_config, |
|
| 860 | ) |
|
| 861 | role = rapi.get_one(test_user.user_id, workspace.workspace_id) |
|
| 862 | assert role.do_notify is True |
|
| 863 | ||
| 864 | ||
| 865 | class TestAccountDisableWorkspaceNotification(FunctionalTest): |
|
| @@ 865-937 (lines=73) @@ | ||
| 862 | assert role.do_notify is True |
|
| 863 | ||
| 864 | ||
| 865 | class TestAccountDisableWorkspaceNotification(FunctionalTest): |
|
| 866 | """ |
|
| 867 | Tests for /api/v2/users/me/workspaces/{workspace_id}/notifications/deactivate # nopep8 |
|
| 868 | """ |
|
| 869 | def test_api_enable_account_workspace_notification__ok__200__nominal(self): |
|
| 870 | # init DB |
|
| 871 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 872 | admin = dbsession.query(models.User) \ |
|
| 873 | .filter(models.User.email == '[email protected]') \ |
|
| 874 | .one() |
|
| 875 | workspace_api = WorkspaceApi( |
|
| 876 | current_user=admin, |
|
| 877 | session=dbsession, |
|
| 878 | config=self.app_config |
|
| 879 | ||
| 880 | ) |
|
| 881 | workspace = WorkspaceApi( |
|
| 882 | current_user=admin, |
|
| 883 | session=dbsession, |
|
| 884 | config=self.app_config, |
|
| 885 | ).create_workspace( |
|
| 886 | 'test workspace', |
|
| 887 | save_now=True |
|
| 888 | ) |
|
| 889 | uapi = UserApi( |
|
| 890 | current_user=admin, |
|
| 891 | session=dbsession, |
|
| 892 | config=self.app_config, |
|
| 893 | ) |
|
| 894 | gapi = GroupApi( |
|
| 895 | current_user=admin, |
|
| 896 | session=dbsession, |
|
| 897 | config=self.app_config, |
|
| 898 | ) |
|
| 899 | groups = [gapi.get_one_with_name('users')] |
|
| 900 | test_user = uapi.create_user( |
|
| 901 | email='[email protected]', |
|
| 902 | password='pass', |
|
| 903 | name='bob', |
|
| 904 | groups=groups, |
|
| 905 | timezone='Europe/Paris', |
|
| 906 | lang='fr', |
|
| 907 | do_save=True, |
|
| 908 | do_notify=False, |
|
| 909 | ) |
|
| 910 | rapi = RoleApi( |
|
| 911 | current_user=admin, |
|
| 912 | session=dbsession, |
|
| 913 | config=self.app_config, |
|
| 914 | ) |
|
| 915 | rapi.create_one(test_user, workspace, UserRoleInWorkspace.READER, with_notif=True) # nopep8 |
|
| 916 | transaction.commit() |
|
| 917 | role = rapi.get_one(test_user.user_id, workspace.workspace_id) |
|
| 918 | assert role.do_notify is True |
|
| 919 | self.testapp.authorization = ( |
|
| 920 | 'Basic', |
|
| 921 | ( |
|
| 922 | '[email protected]', |
|
| 923 | 'pass', |
|
| 924 | ) |
|
| 925 | ) |
|
| 926 | self.testapp.put_json('/api/v2/users/me/workspaces/{workspace_id}/notifications/deactivate'.format( # nopep8 |
|
| 927 | user_id=test_user.user_id, |
|
| 928 | workspace_id=workspace.workspace_id |
|
| 929 | ), status=204) |
|
| 930 | dbsession = get_tm_session(self.session_factory, transaction.manager) |
|
| 931 | rapi = RoleApi( |
|
| 932 | current_user=admin, |
|
| 933 | session=dbsession, |
|
| 934 | config=self.app_config, |
|
| 935 | ) |
|
| 936 | role = rapi.get_one(test_user.user_id, workspace.workspace_id) |
|
| 937 | assert role.do_notify is False |
|
| 938 | ||
| 939 | ||
| 940 | class TestAccountWorkspaceEndpoint(FunctionalTest): |
|