def test_get_notifiable_roles(self): admin = self.session.query(User) \ .filter(User.email == '*****@*****.**').one() wapi = WorkspaceApi( session=self.session, config=self.app_config, current_user=admin, ) w = wapi.create_workspace(label='workspace w', save_now=True) uapi = UserApi( session=self.session, current_user=admin, config=self.config ) u = uapi.create_minimal_user(email='[email protected]', save_now=True) eq_([], wapi.get_notifiable_roles(workspace=w)) rapi = RoleApi( session=self.session, current_user=admin, config=self.app_config, ) r = rapi.create_one(u, w, UserRoleInWorkspace.READER, with_notif=True) eq_([r, ], wapi.get_notifiable_roles(workspace=w)) u.is_active = False eq_([], wapi.get_notifiable_roles(workspace=w))
def test_unit__create_minimal_user__ok__nominal_case(self): api = UserApi( current_user=None, session=self.session, config=self.config, ) u = api.create_minimal_user('bob@bob') assert u.email == 'bob@bob' assert u.display_name == 'bob'
def test_unit__get_one__ok__nominal_case(self): api = UserApi( current_user=None, session=self.session, config=self.config, ) u = api.create_minimal_user('titi@titi') api.update(u, 'titi', 'titi@titi', 'pass', do_save=True) one = api.get_one(u.user_id) eq_(u.user_id, one.user_id)
def test_unit__get_all__ok__nominal_case(self): api = UserApi( current_user=None, session=self.session, config=self.config, ) u1 = api.create_minimal_user('bibi@bibi') users = api.get_all() # u1 + Admin user from BaseFixture assert 2 == len(users)
def test_unit__user_with_email_exists__ok__nominal_case(self): api = UserApi( current_user=None, session=self.session, config=self.config, ) u = api.create_minimal_user('bibi@bibi') api.update(u, 'bibi', 'bibi@bibi', 'pass', do_save=True) transaction.commit() eq_(True, api.user_with_email_exists('bibi@bibi')) eq_(False, api.user_with_email_exists('unknown'))
def test_get_one_by_email(self): api = UserApi( current_user=None, session=self.session, config=self.config, ) u = api.create_minimal_user('bibi@bibi') self.session.flush() api.update(u, 'bibi', 'bibi@bibi', 'pass', do_save=True) uid = u.user_id transaction.commit() eq_(uid, api.get_one_by_email('bibi@bibi').user_id)
def test_unit__create_minimal_user_and_update__ok__nominal_case(self): api = UserApi( current_user=None, session=self.session, config=self.config, ) u = api.create_minimal_user('bob@bob') api.update(u, 'bob', 'bob@bob', 'pass', do_save=True) nu = api.get_one_by_email('bob@bob') assert nu is not None assert nu.email == 'bob@bob' assert nu.display_name == 'bob' assert nu.validate_password('pass')
def test_unit__get_all_manageable(self): admin = self.session.query(User) \ .filter(User.email == '*****@*****.**').one() uapi = UserApi( session=self.session, current_user=admin, config=self.config, ) # Checks a case without workspaces. wapi = WorkspaceApi( session=self.session, current_user=admin, config=self.app_config, ) eq_([], wapi.get_all_manageable()) # Checks an admin gets all workspaces. w4 = wapi.create_workspace(label='w4') w3 = wapi.create_workspace(label='w3') w2 = wapi.create_workspace(label='w2') w1 = wapi.create_workspace(label='w1') eq_([w1, w2, w3, w4], wapi.get_all_manageable()) # Checks a regular user gets none workspace. gapi = GroupApi( session=self.session, current_user=None, config=self.app_config, ) u = uapi.create_minimal_user('[email protected]', [gapi.get_one(Group.TIM_USER)], True) wapi = WorkspaceApi( session=self.session, current_user=u, config=self.app_config, ) rapi = RoleApi( session=self.session, current_user=u, config=self.app_config, ) rapi.create_one(u, w4, UserRoleInWorkspace.READER, False) rapi.create_one(u, w3, UserRoleInWorkspace.CONTRIBUTOR, False) rapi.create_one(u, w2, UserRoleInWorkspace.CONTENT_MANAGER, False) rapi.create_one(u, w1, UserRoleInWorkspace.WORKSPACE_MANAGER, False) eq_([], wapi.get_all_manageable()) # Checks a manager gets only its own workspaces. u.groups.append(gapi.get_one(Group.TIM_MANAGER)) rapi.delete_one(u.user_id, w2.workspace_id) rapi.create_one(u, w2, UserRoleInWorkspace.WORKSPACE_MANAGER, False) eq_([w1, w2], wapi.get_all_manageable())