def test_delete_organization_with_user(self, context): step("Create an organization") test_org = Organization.api_create(context) step("Add new platform user to the organization") User.api_create_by_adding_to_organization(context, test_org.guid) step("Delete the organization") test_org.api_delete() step("Check that the organization is not on org list") assertions.assert_not_in_with_retry(test_org, Organization.api_get_list)
def users(cls, request, admin_client, test_org_manager, test_org_manager_client, class_context): cls.context = class_context # TODO no longer needed when this class removes unittest dependency cls.step("Create test organization") cls.test_org = Organization.api_create(class_context) cls.step("Create users for tests") cls.manager = User.api_create_by_adding_to_organization(class_context, org_guid=cls.test_org.guid, roles=User.ORG_ROLES["manager"]) cls.manager_client = cls.manager.login() cls.updated_user = User.api_create_by_adding_to_organization(class_context, org_guid=cls.test_org.guid, roles=[]) cls.user_not_in_test_org = test_org_manager cls.client_not_in_test_org = test_org_manager_client
def users(cls, request, test_org, class_context): cls.step("Create test users") manager = User.api_create_by_adding_to_organization( class_context, org_guid=test_org.guid) cls.manager_client = manager.login() auditor = User.api_create_by_adding_to_organization( class_context, org_guid=test_org.guid, roles=User.ORG_ROLES["auditor"]) cls.auditor_client = auditor.login() billing_manager = User.api_create_by_adding_to_organization( class_context, org_guid=test_org.guid, roles=User.ORG_ROLES["billing_manager"]) cls.billing_manager_client = billing_manager.login()
def test_add_new_user_with_no_roles(self): self.step("Create new user by adding to an organization with no roles") expected_roles = [] self.user = User.api_create_by_adding_to_organization( self.context, org_guid=self.test_org.guid, roles=expected_roles) self.assert_user_in_org_and_roles(self.user, self.test_org.guid, expected_roles)
def space_and_users(cls, request, test_org, class_context): cls.test_space = Space.api_create(org=test_org) cls.test_users = [ User.api_create_by_adding_to_organization(class_context, org_guid=test_org.guid) for _ in range(2) ]
def test_admin_adds_new_user_one_role(self): # TODO parametrize self.step("Create new user by adding to an organization with one role") expected_roles = User.ORG_ROLES["auditor"] self.user = User.api_create_by_adding_to_organization( self.context, org_guid=self.test_org.guid, roles=expected_roles) self.assert_user_in_org_and_roles(self.user, self.test_org.guid, expected_roles)
def test_admin_adds_new_user_all_roles(self): self.step( "Create new user by adding to an organization with all roles") expected_roles = self.ALL_ROLES self.user = User.api_create_by_adding_to_organization( self.context, org_guid=self.test_org.guid, roles=expected_roles) self.assert_user_in_org_and_roles(self.user, self.test_org.guid, expected_roles)
def test_non_manager_cannot_update_org_user(self): self.step("Check that non-manager cannot update another user's roles") non_manager = User.api_create_by_adding_to_organization(self.context, org_guid=self.test_org.guid, roles=self.NON_MANAGER_ROLES) non_manager_client = non_manager.login() org_users = User.api_get_list_via_organization(org_guid=self.test_org.guid) self.assertRaisesUnexpectedResponse(HttpStatus.CODE_FORBIDDEN, HttpStatus.MSG_FORBIDDEN, self.updated_user.api_update_org_roles, self.test_org.guid, new_roles=User.ORG_ROLES["auditor"], client=non_manager_client) self.assertListEqual(User.api_get_list_via_organization(org_guid=self.test_org.guid), org_users)
def test_org_manager_adds_new_user(self): self.step("Org manager adds a new user to an organization with") inviting_client = self.org_manager_client expected_roles = User.ORG_ROLES["billing_manager"] self.user = User.api_create_by_adding_to_organization( self.context, org_guid=self.test_org.guid, roles=expected_roles, inviting_client=inviting_client) self.assert_user_in_org_and_roles(self.user, self.test_org.guid, expected_roles)
def test_1_check_created_user(self, class_context): step("Create test organization manager") self.__class__.test_org_manager = User.api_create_by_adding_to_organization( class_context, self.test_org.guid) self.__class__.test_org_manager_client = self.test_org_manager.login() step("Check user is in test organization") org_hdfs_user_dirs = self._list_hdfs_directories( self.USER_PATH.format(self.test_org.guid)) self._assert_directory_in_hdfs(org_hdfs_user_dirs, name=self.test_org_manager.guid, owner=self.test_org_manager.guid, group=self.test_org.guid)
def user_clients(cls, request, test_org, test_space, class_context): cls.context = class_context # TODO move to methods when dependency on unittest is removed second_test_org = Organization.api_create(class_context) org_manager = User.api_create_by_adding_to_organization( class_context, test_org.guid) space_manager_in_org = User.api_create_by_adding_to_space( class_context, test_org.guid, test_space.guid) org_user = User.api_create_by_adding_to_organization( class_context, test_org.guid, roles=User.ORG_ROLES["auditor"]) other_org_manager = User.api_create_by_adding_to_organization( class_context, second_test_org.guid) other_user = User.api_create_by_adding_to_organization( class_context, second_test_org.guid, roles=[]) cls.user_clients = { "admin": HttpClientFactory.get(ConsoleConfigurationProvider.get()), "org_manager": org_manager.login(), "space_manager_in_org": space_manager_in_org.login(), "org_user": org_user.login(), "other_org_manager": other_org_manager.login(), "other_user": other_user.login() }
def test_org_manager(request, test_org): context = Context() log_fixture("test_org_manager: Add org manager to test org") test_org_manager = User.api_create_by_adding_to_organization( context, org_guid=test_org.guid) TestData.test_org_manager = test_org_manager def fin(): log_finalizer("test_org_manager: Delete test org manager") context.cleanup() request.addfinalizer(fin) return test_org_manager
def test_org_manager_adds_existing_user(self): self.step("Add a manager to the organization.") org_manager = User.api_create_by_adding_to_organization( self.context, org_guid=self.test_org.guid, roles=User.ORG_ROLES["manager"]) manager_client = org_manager.login() expected_roles = User.ORG_ROLES["auditor"] self.step("The new manager adds a platform user to the organization.") self.test_user.api_add_to_organization(self.test_org.guid, roles=expected_roles, client=manager_client) self.assert_user_in_org_and_roles(self.test_user, self.test_org.guid, expected_roles)
def test_non_manager_cannot_add_existing_user_to_org(self): self.step("Add a non-manager to the organization.") non_manager = User.api_create_by_adding_to_organization( self.context, org_guid=self.test_org.guid, roles=User.ORG_ROLES["auditor"]) non_manager_client = non_manager.login() self.step( "Check that the non-manager is able to add a platform user to the org" ) self.assertRaisesUnexpectedResponse( HttpStatus.CODE_FORBIDDEN, HttpStatus.MSG_FORBIDDEN, self.test_user.api_add_to_organization, org_guid=self.test_org.guid, roles=User.ORG_ROLES["auditor"], client=non_manager_client) self._assert_user_not_in_org(self.test_user, self.test_org.guid)
def test_update_role(self, client, is_authorized): new_roles = User.SPACE_ROLES["auditor"] step("Try to change user space role using every client type.") test_user = User.api_create_by_adding_to_organization( self.context, TestData.test_org.guid) if is_authorized: test_user.api_update_space_roles(TestData.test_space.guid, new_roles=new_roles, 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, test_user.api_update_space_roles, TestData.test_space.guid, new_roles=new_roles, client=self.user_clients[client])
def test_add_existing_user(self, client, is_authorized): step("Try to add existing user to space with every client type.") test_user = User.api_create_by_adding_to_organization( self.context, TestData.test_org.guid) if is_authorized: test_user.api_add_to_space(TestData.test_space.guid, TestData.test_org.guid, 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])
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"
def test_non_manager_cannot_add_new_user_to_org(self): self.step("Add a non-manager to the organization.") non_manager = User.api_create_by_adding_to_organization( self.context, org_guid=self.test_org.guid, roles=User.ORG_ROLES["auditor"]) self.user = non_manager non_manager_client = non_manager.login() self.step( "Check that user cannot be added to organization by non-manager") org_users = User.api_get_list_via_organization(self.test_org.guid) self.assertRaisesUnexpectedResponse( HttpStatus.CODE_FORBIDDEN, HttpStatus.MSG_FORBIDDEN, User.api_create_by_adding_to_organization, self.context, org_guid=self.test_org.guid, roles=User.ORG_ROLES["auditor"], inviting_client=non_manager_client) # assert user list did not change self.assertListEqual( User.api_get_list_via_organization(self.test_org.guid), org_users)
def user(cls, request, test_org, class_context): cls.step("Create new platform user by adding to the organization") cls.test_user = User.api_create_by_adding_to_organization( class_context, test_org.guid)
def user(cls, request, test_org, class_context): cls.test_user = User.api_create_by_adding_to_organization( class_context, test_org.guid)
def user(self, request, test_org, context): self.step("Create test user") self.test_user = User.api_create_by_adding_to_organization( context, org_guid=test_org.guid)
def setup(cls, class_context): cls.step("Create test org") cls.test_org = Organization.api_create(class_context) cls.step("Add org manager") User.api_create_by_adding_to_organization(class_context, org_guid=cls.test_org.guid)
def another_org_client(self, context, another_org): step("Create org manager in another org") user = User.api_create_by_adding_to_organization( org_guid=another_org.guid, context=context) return user.login()