예제 #1
0
 def test_manager_can_get_org_users(self):
     self.step("Check that manager can get list of users in org")
     expected_users = User.api_get_list_via_organization(
         org_guid=TestData.test_org.guid)
     user_list = User.api_get_list_via_organization(
         org_guid=TestData.test_org.guid, client=self.manager_client)
     self.assertUnorderedListEqual(user_list, expected_users)
 def test_cannot_update_user_with_invalid_guid(self):
     # TODO implement non-existing guid
     self.step("Check that updating user which is not in an organization returns an error")
     invalid_guid = "invalid-user-guid"
     org_users = User.api_get_list_via_organization(org_guid=self.test_org.guid)
     self.assertRaisesUnexpectedResponse(HttpStatus.CODE_BAD_REQUEST, HttpStatus.MSG_WRONG_UUID_FORMAT_EXCEPTION,
                                         user_management.api_update_org_user_roles, org_guid=self.test_org.guid,
                                         user_guid=invalid_guid, new_roles=User.ORG_ROLES["billing_manager"])
     self.assertListEqual(User.api_get_list_via_organization(org_guid=self.test_org.guid), org_users)
 def test_cannot_update_user_which_is_not_in_org(self):
     self.step("Check that user not in org cannot be updated")
     org_users = User.api_get_list_via_organization(org_guid=self.test_org.guid)
     expected_message = HttpStatus.MSG_USER_NOT_EXIST_IN_ORGANIZATION.format(self.user_not_in_test_org.guid,
                                                                             self.test_org.guid)
     self.assertRaisesUnexpectedResponse(HttpStatus.CODE_NOT_FOUND, expected_message,
                                         self.user_not_in_test_org.api_update_org_roles, org_guid=self.test_org.guid,
                                         new_roles=User.ORG_ROLES["auditor"])
     self.assertListEqual(User.api_get_list_via_organization(org_guid=self.test_org.guid), org_users)
 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)
예제 #5
0
 def test_cannot_add_new_user_incorrect_role(self):
     self.step(
         "Check that error is raised when trying to add user using incorrect roles"
     )
     roles = ["i-don't-exist"]
     org_users = User.api_get_list_via_organization(self.test_org.guid)
     self.assertRaisesUnexpectedResponse(
         HttpStatus.CODE_BAD_REQUEST,
         HttpStatus.MSG_EMPTY,
         User.api_create_by_adding_to_organization,
         self.context,
         org_guid=self.test_org.guid,
         roles=roles)
     # assert user list did not change
     self.assertListEqual(
         User.api_get_list_via_organization(self.test_org.guid), org_users)
예제 #6
0
def test_add_new_user_to_and_delete_from_org(core_org, context):
    """Add New User to and Delete from Organization"""
    step("Add new user to organization")
    test_user, test_org = onboarding.onboard(context, check_email=False)
    test_user.api_add_to_organization(
        core_org.guid,
        roles=User.ORG_ROLES["manager"],
    )
    step("Check that the user is added")
    users = User.api_get_list_via_organization(org_guid=core_org.guid)
    assert test_user in users
    step("Delete the user from the organization")
    test_user.api_delete_from_organization(org_guid=core_org.guid)
    step("Check that the user is in the organization")
    users = User.api_get_list_via_organization(org_guid=core_org.guid)
    assert test_user not in users
예제 #7
0
 def test_cannot_add_user_with_non_email_username(self):
     self.step(
         "Check that user with non valid username cannot be added to an organization"
     )
     username = "******"
     roles = self.ALL_ROLES
     org_users = User.api_get_list_via_organization(self.test_org.guid)
     self.assertRaisesUnexpectedResponse(
         HttpStatus.CODE_BAD_REQUEST,
         HttpStatus.MSG_EMAIL_ADDRESS_NOT_VALID,
         User.api_create_by_adding_to_organization,
         self.context,
         org_guid=self.test_org.guid,
         username=username,
         roles=roles)
     # assert user list did not change
     self.assertListEqual(
         User.api_get_list_via_organization(self.test_org.guid), org_users)
예제 #8
0
 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)
예제 #9
0
def assert_user_in_org_and_roles(invited_user, org_guid, expected_roles):
    step(
        "Check that the user is in the organization with expected roles ({}).".
        format(expected_roles))
    org_users = User.api_get_list_via_organization(org_guid)
    assert invited_user in org_users, "Invited user is not on org users list"
    org_user = next(user for user in org_users
                    if user.username == invited_user.username)
    org_user_roles = list(org_user.org_roles.get(org_guid, []))
    assert_unordered_list_equal(
        org_user_roles, list(expected_roles),
        "User's roles in org: {}, expected {}".format(org_user_roles,
                                                      list(expected_roles)))
예제 #10
0
 def test_delete_user_from_space(self):
     self.step("Add the user to space")
     TestData.test_org_manager.api_add_to_space(self.test_space.guid,
                                                TestData.test_org.guid)
     self.step("Delete the user from space")
     TestData.test_org_manager.api_delete_from_space(self.test_space.guid)
     self.assertNotInWithRetry(TestData.test_org_manager,
                               User.api_get_list_via_space,
                               self.test_space.guid)
     self.step("Check that the user is still in the organization")
     org_users = User.api_get_list_via_organization(
         org_guid=TestData.test_org.guid)
     self.assertIn(TestData.test_org_manager, org_users,
                   "User is not in the organization")
 def _assert_user_not_in_org(self, user, org_guid):
     # TODO refactor to fixtures.assertions
     self.step("Check that the user is not in the organization.")
     org_users = User.api_get_list_via_organization(org_guid)
     self.assertNotIn(user, org_users,
                      "User is among org users, although they shouldn't")