def test_get_user_list_from_space(self): self.step("Check that space is empty") self.assertEqual([], User.api_get_list_via_space(self.test_space.guid), "List is not empty") self.step("Add users to space") for user in self.test_users: user.api_add_to_space(self.test_space.guid, TestData.test_org.guid) space_user_list = User.api_get_list_via_space(self.test_space.guid) self.assertListEqual(self.test_users, space_user_list)
def test_cannot_update_non_existing_space_user(self): invalid_guid = "invalid-user-guid" roles = User.SPACE_ROLES["auditor"] self.step( "Check that updating user which is not in space returns error") space_users = User.api_get_list_via_space(self.test_space.guid) self.assertRaisesUnexpectedResponse( HttpStatus.CODE_BAD_REQUEST, HttpStatus.MSG_WRONG_UUID_FORMAT_EXCEPTION, user_management.api_update_space_user_roles, self.test_space.guid, invalid_guid, roles) self.assertListEqual(User.api_get_list_via_space(self.test_space.guid), space_users)
def test_add_new_user_to_and_delete_from_space(core_org, core_space, context): """Add New User to and Delete from Space""" step("Add new user to space") test_user, test_org = onboarding.onboard(context, check_email=False) test_user.api_add_to_space(core_space.guid, core_org.guid, roles=User.SPACE_ROLES["manager"]) step("Check that the user is added") users = User.api_get_list_via_space(space_guid=core_space.guid) assert test_user in users step("Remove the user from space") test_user.api_delete_from_space(space_guid=core_space.guid) step("Check that the user was deleted") users = User.api_get_list_via_space(space_guid=core_space.guid) assert test_user not in users
def test_cannot_add_user_with_incorrect_role(self): space_users = User.api_get_list_via_space(self.test_space.guid) roles = ["i-don't-exist"] self.step( "Check that error is raised when trying to add user using incorrect roles" ) self.assertRaisesUnexpectedResponse(HttpStatus.CODE_BAD_REQUEST, HttpStatus.MSG_BAD_REQUEST, User.api_create_by_adding_to_space, self.context, self.test_org.guid, self.test_space.guid, roles=roles) self.step("Assert user list did not change") self.assertListEqual(User.api_get_list_via_space(self.test_space.guid), space_users, "User with incorrect roles was added to space")
def _assert_user_in_space_with_roles(expected_user, space_guid): step("Check that the user is on the list of space users") space_users = User.api_get_list_via_space(space_guid) assert expected_user in space_users space_user = next(user for user in space_users if user.guid == expected_user.guid) step("Check that the user has expected space roles") space_user_roles = space_user.space_roles.get(space_guid) expected_roles = expected_user.space_roles.get(space_guid) assert space_user_roles == expected_roles, "{} space roles are not equal".format( expected_user)
def _assert_user_in_space_with_roles(self, expected_user, space_guid): # TODO move to TapTestCase self.step("Check that the user is on the list of space users") space_users = User.api_get_list_via_space(space_guid) self.assertIn(expected_user, space_users) space_user = next(user for user in space_users if user.guid == expected_user.guid) self.step("Check that the user has expected space roles") space_user_roles = space_user.space_roles.get(space_guid) expected_roles = expected_user.space_roles.get(space_guid) self.assertUnorderedListEqual( space_user_roles, expected_roles, "{} space roles are not equal".format(expected_user))
def test_add_new_user(self, client, is_authorized): step("Try to add new user with each client type.") user_list = User.api_get_list_via_space(TestData.test_space.guid) if is_authorized: test_user = User.api_create_by_adding_to_space( self.context, TestData.test_org.guid, TestData.test_space.guid, inviting_client=self.user_clients[client]) self._assert_user_in_space_with_roles(test_user, TestData.test_space.guid) else: assert_raises_http_exception( HttpStatus.CODE_FORBIDDEN, HttpStatus.MSG_FORBIDDEN, User.api_create_by_adding_to_space, self.context, TestData.test_org.guid, TestData.test_space.guid, inviting_client=self.user_clients[client]) assert User.api_get_list_via_space( TestData.test_space.guid) == user_list, "User was added"
def test_get_user_list(self, client, is_authorized): test_user = User.api_create_by_adding_to_space( self.context, TestData.test_org.guid, TestData.test_space.guid) step("Try to get user list from space by using every client type.") if is_authorized: user_list = User.api_get_list_via_space( TestData.test_space.guid, client=self.user_clients[client]) assert test_user in user_list, "User {} was not found in list".format( test_user) else: assert_raises_http_exception(HttpStatus.CODE_FORBIDDEN, HttpStatus.MSG_FORBIDDEN, User.api_get_list_via_space, TestData.test_space.guid, client=self.user_clients[client])
def test_delete_user(self, client, is_authorized): test_user = User.api_create_by_adding_to_organization( self.context, TestData.test_org.guid) step("Try to delete user from space using every client type") test_user.api_add_to_space(org_guid=TestData.test_org.guid, space_guid=TestData.test_space.guid) self._assert_user_in_space_with_roles(test_user, TestData.test_space.guid) if is_authorized: test_user.api_delete_from_space(TestData.test_space.guid, client=self.user_clients[client]) assert_not_in_with_retry(test_user, User.api_get_list_via_space, TestData.test_space.guid) else: assert_raises_http_exception(HttpStatus.CODE_FORBIDDEN, HttpStatus.MSG_FORBIDDEN, test_user.api_delete_from_space, TestData.test_space.guid, client=self.user_clients[client]) assert test_user in User.api_get_list_via_space( TestData.test_space.guid), "User was deleted"