def test_invite_user_new(self): """Test for inviting a new user.""" project_setup = self.create_project_and_owner(username_is_email=True) new_email = uuid4().hex + "@stacktask-tempest.com" new_password = uuid4().hex auth = { "name": project_setup['owner']['username'], "password": project_setup['owner']['password'], "project_id": project_setup['project']['id'], "url": self.identity_utils.identity_client.base_url, } api.user_invite( auth, {"username": new_email, "email": new_email, "roles": ["Member"]} ) tasks = api.get_tasks(auth, {}).json() auth['user_token'] = self.identity_utils.identity_client.token tokens = api.get_tokens( auth, {}, {'task_id': {"exact": tasks['tasks'][0]['uuid']}} ).json() token = tokens['tokens'][0]['token'] api.token_submit(auth, token, {"password": new_password}).json() # confirm user has been created user = identity.get_user_by_username( self.identity_utils.identity_client, project_setup['project']['id'], new_email ) self.add_clean_up_user(user['id']) # and has member role: roles = self.identity_utils.identity_client.list_user_roles( project_setup['project']['id'], user['id']) has_member = False for role in roles['roles']: if role['name'] == "Member": has_member = True self.assertTrue(has_member)
def test_invite_user_existing(self): """Test for inviting an existing user.""" project_setup = self.create_project_and_owner(username_is_email=True) project2_setup = self.create_project_and_owner(username_is_email=True) auth = { "name": project_setup['owner']['username'], "password": project_setup['owner']['password'], "project_id": project_setup['project']['id'], "url": self.identity_utils.identity_client.base_url, } api.user_invite( auth, { "username": project2_setup['owner']['username'], "email": project2_setup['owner']['email'], "roles": ["Member"]} ) tasks = api.get_tasks(auth, {}).json() auth['user_token'] = self.identity_utils.identity_client.token tokens = api.get_tokens( auth, {}, {'task_id': {"exact": tasks['tasks'][0]['uuid']}} ).json() token = tokens['tokens'][0]['token'] api.token_submit(auth, token, {"confirm": True}) # confirm user has member role in first project roles = self.identity_utils.identity_client.list_user_roles( project_setup['project']['id'], project2_setup['owner']['id']) has_member = False for role in roles['roles']: if role['name'] == "Member": has_member = True self.assertTrue(has_member)
def test_cancel_user_invite(self): """Test canceling of a user invite.""" project_setup = self.create_project_and_owner(username_is_email=True) new_email = "*****@*****.**" new_password = uuid4().hex auth = { "name": project_setup['owner']['username'], "password": project_setup['owner']['password'], "project_id": project_setup['project']['id'], "url": self.identity_utils.identity_client.base_url, } api.user_invite( auth, {"username": new_email, "email": new_email, "roles": ["Member"]} ) tasks = api.get_tasks(auth, {}).json() api.user_revoke( auth, tasks['tasks'][0]['uuid'] ) auth['user_token'] = self.identity_utils.identity_client.token tokens = api.get_tokens( auth, {}, {'task_id': {"exact": tasks['tasks'][0]['uuid']}} ).json() token = tokens['tokens'][0]['token'] response = api.token_submit(auth, token, {"password": new_password}) self.assertEqual(response.status_code, 400) self.assertEqual( response.json(), {u'errors': [u'This task has been cancelled.']})