コード例 #1
0
 def test_add_new_pending_invitation_twice_for_the_same_user(self):
     self.step("Send invitation two times for a single user")
     invitation = Invitation.api_send(self.context)
     Invitation.api_send(self.context, username=invitation.username)
     invited_users = [i.username for i in Invitation.api_get_list()]
     self.step("Check that there is only one invitation for the user")
     self.assertEqual(invited_users.count(invitation.username), 1, "More than one invitation for the user")
コード例 #2
0
    def test_user_cannot_register_without_password(self, context, test_org):
        """
        <b>Description:</b>
        Checks if the user registration without password fails.

        <b>Input data:</b>
        1. Email address.

        <b>Expected results:</b>
        Test passes when 400 Bad request HTTP status is returned on attempt of user registration without password and
        the user is not created.

        <b>Steps:</b>
        1. Invite a user.
        2. Check that an error is returned when the user tries to register without a password.
        3. Check that the user was not created.
        """
        step("Invite a new user")
        invitation = Invitation.api_send(context)
        step(
            "Check that an error is returned when the user tries to register without a password"
        )
        assert_raises_http_exception(HttpStatus.CODE_BAD_REQUEST,
                                     HttpStatus.MSG_PASSWORD_CANNOT_BE_EMPTY,
                                     user_management.api_register_new_user,
                                     code=invitation.code,
                                     org_name=generate_test_object_name())
        step("Check that the user was not created")
        username_list = [
            user.username for user in User.get_all_users(test_org.guid)
        ]
        assert invitation.username not in username_list, "User was created"
コード例 #3
0
    def test_simple_onboarding(self, context, test_org):
        """
        <b>Description:</b>
        Checks if onboarding functionality works.

        <b>Input data:</b>
        1. Email address.

        <b>Expected results:</b>
        Test passes when exactly one invitation was sent to the user; content, subject and sender of invitation are
        correct and user was correctly added to the organization with appropriate role.

        <b>Steps:</b>
        1. Invite new user.
        2. Register the new user.
        3. Check that the user and their organization exist.
        """
        step("Send an invite to a new user")
        invitation = Invitation.api_send(context)
        messages = gmail_api.wait_for_messages_to(
            recipient=invitation.username, messages_number=1)
        assert len(
            messages
        ) == 1, "There are {} messages for the user. Expected: 1".format(
            len(messages))
        message = messages[0]
        self._assert_message_correct(message["subject"], message["content"],
                                     message["sender"])
        step("Register the new user")
        user = onboarding.register(context=context,
                                   org_guid=test_org.guid,
                                   code=invitation.code,
                                   username=invitation.username)
        step("Check that the user and their organization exist")
        assert_user_in_org_and_role(user, test_org.guid, User.ORG_ROLE["user"])
コード例 #4
0
 def test_cannot_delete_not_existing_pending_invitation(self):
     self.step("Try to delete not existing invitation")
     username = "******"
     invitation = Invitation(username=username)
     self.assertRaisesUnexpectedResponse(HttpStatus.CODE_NOT_FOUND,
                                         HttpStatus.MSG_NO_PENDING_INVITATION_FOR.format(username),
                                         invitation.api_delete)
コード例 #5
0
 def test_accepting_invitation_deletes_it_from_pending_list(self):
     self.step("Invite new user")
     invitation = Invitation.api_send(self.context)
     self.step("Register user with the received code")
     onboarding.register(self.context, code=invitation.code, username=invitation.username)
     self.step("Check that invitation is no longer present in pending invitation list")
     self.assertNotInWithRetry(invitation, Invitation.api_get_list)
コード例 #6
0
 def test_delete_pending_invitation(self):
     self.step("Invite new user")
     invitation = Invitation.api_send(self.context)
     self.assertInWithRetry(invitation, Invitation.api_get_list)
     self.step("Delete pending user invitation")
     invitation.api_delete()
     self.assertNotInWithRetry(invitation, Invitation.api_get_list)
     self.step("Check that the user cannot register after deletion of pending invitation")
     self.assertRaisesUnexpectedResponse(HttpStatus.CODE_FORBIDDEN, HttpStatus.MSG_EMPTY,
                                         onboarding.register, self.context, code=invitation.code,
                                         username=invitation.username)
コード例 #7
0
 def test_resend_pending_invitation(self):
     self.step("Invite new user")
     invitation = Invitation.api_send(self.context)
     self.step("Check that the user received the message")
     messages = gmail_api.wait_for_messages_to(recipient=invitation.username, messages_number=1)
     self.assertEqual(len(messages), 1)
     self.step("Resend invitation")
     invitation.api_resend()
     self.step("Check that the user received the new message")
     messages = gmail_api.wait_for_messages_to(recipient=invitation.username, messages_number=2)
     self.assertEqual(len(messages), 2)
     self.step("Register user with the received code")
     user, org = onboarding.register(self.context, code=invitation.code, username=invitation.username)
     self.assert_user_in_org_and_roles(user, org.guid, User.ORG_ROLES["manager"])
コード例 #8
0
def cleanup_test_data():
    core_org_guid = core_org().guid
    test_object_models = [
        {'name': 'data set', 'objects_list': DataSet.api_get_list(), 'name_attribute': 'title'},
        {'name': 'transfer', 'objects_list': Transfer.api_get_list(), 'name_attribute': 'title'},
        {'name': 'user', 'objects_list': User.get_list_in_organization(org_guid=core_org_guid), 'name_attribute': 'username'},
        {'name': 'invitation', 'objects_list': Invitation.api_get_list(), 'name_attribute': 'username'},
        {'name': 'application', 'objects_list': Application.get_list(), 'name_attribute': 'name'},
        {'name': 'service', 'objects_list': ServiceInstance.get_list(), 'name_attribute': 'name'},
        {'name': 'offering', 'objects_list': ServiceOffering.get_list(), 'name_attribute': 'label'},
        {'name': 'scoring engine model', 'objects_list': ScoringEngineModel.get_list(org_guid=core_org_guid),
         'name_attribute': 'name'}
    ]
    for model in test_object_models:
        _cleanup_test_data(**model)
コード例 #9
0
 def test_user_cannot_register_with_no_organization_name(self, context):
     step("Invite a new user")
     invitation = Invitation.api_send(context)
     step(
         "Check that an error is returned when user registers without passing an org name"
     )
     assert_raises_http_exception(
         HttpStatus.CODE_BAD_REQUEST,
         HttpStatus.MSG_ORGANIZATION_CANNOT_CONTAIN_ONLY_WHITESPACES,
         user_management.api_register_new_user,
         code=invitation.code,
         password=User.generate_password())
     step("Check that the user was not created")
     username_list = [user.username for user in User.get_all_users()]
     assert invitation.username not in username_list, "User was created"
コード例 #10
0
 def test_user_cannot_register_already_existing_organization(
         self, context, test_org):
     step("Invite a new user")
     invitation = Invitation.api_send(context)
     step(
         "Check that an error is returned when the user registers with an already-existing org name"
     )
     assert_raises_http_exception(
         HttpStatus.CODE_CONFLICT,
         HttpStatus.MSG_ORGANIZATION_ALREADY_EXISTS.format(test_org.name),
         onboarding.register,
         context=context,
         code=invitation.code,
         username=invitation.username,
         org_name=test_org.name)
     step("Check that the user was not created")
     username_list = [user.username for user in User.get_all_users()]
     assert invitation.username not in username_list, "User was created"
コード例 #11
0
    def test_cannot_use_the_same_activation_code_twice(self, context,
                                                       test_org):
        """
        <b>Description:</b>
        Checks if the same activation code cannot be used twice.

        <b>Input data:</b>
        1. Email address.
        2. User password.

        <b>Expected results:</b>
        Test passes when 403 Forbidden HTTP status is returned on attempt of registering a user twice with the same
        code.

        <b>Steps:</b>
        1. Invite a user.
        2. The new user registers.
        3. Check that error is returned when the user tries to use code twice.
        """
        step("Invite a user")
        invitation = Invitation.api_send(context)
        step("The new user registers")
        onboarding.register(context=context,
                            org_guid=test_org.guid,
                            code=invitation.code,
                            username=invitation.username)
        step(
            "Check that error is returned when the user tries to use code twice"
        )
        assert_raises_http_exception(HttpStatus.CODE_FORBIDDEN,
                                     HttpStatus.MSG_EMPTY,
                                     onboarding.register,
                                     context=context,
                                     org_guid=test_org.guid,
                                     code=invitation.code,
                                     username=invitation.username)
コード例 #12
0
 def test_cannot_resend_invitation_providing_empty_name(self):
     invitation = Invitation(username="")
     self.assertRaisesUnexpectedResponse(HttpStatus.CODE_METHOD_NOT_ALLOWED,
                                         HttpStatus.MSG_METHOD_NOT_SUPPORTED.format("POST"),
                                         invitation.api_resend)
コード例 #13
0
 def test_cannot_resend_not_existing_pending_invitation(self):
     username = "******"
     invitation = Invitation(username=username)
     self.assertRaisesUnexpectedResponse(HttpStatus.CODE_NOT_FOUND,
                                         HttpStatus.MSG_NO_PENDING_INVITATION_FOR.format(username),
                                         invitation.api_resend)
コード例 #14
0
 def test_add_new_pending_invitation(self):
     self.step("Invite new user")
     invitation = Invitation.api_send(self.context)
     self.step("Check that the user is in the pending invitation list")
     self.assertInWithRetry(invitation, Invitation.api_get_list)
コード例 #15
0
if __name__ == "__main__":

    all_data_sets = DataSet.api_get_list()
    test_data_sets = [x for x in all_data_sets if is_test_object_name(x.title)]
    log_deleted_objects(test_data_sets, "data set")
    fixtures.tear_down_test_objects(test_data_sets)

    all_transfers = Transfer.api_get_list()
    test_transfers = [x for x in all_transfers if is_test_object_name(x.title)]
    log_deleted_objects(test_transfers, "transfer")
    fixtures.tear_down_test_objects(test_transfers)

    all_users = User.cf_api_get_all_users()
    test_users = [x for x in all_users if is_test_object_name(x.username)]
    log_deleted_objects(test_users, "user")
    fixtures.tear_down_test_objects(test_users)

    all_pending_invitations = Invitation.api_get_list()
    test_invitations = [
        x for x in all_pending_invitations if is_test_object_name(x.username)
    ]
    log_deleted_objects(test_invitations, "invitation")
    fixtures.tear_down_test_objects(test_invitations)

    all_orgs = Organization.cf_api_get_list()
    test_orgs = [x for x in all_orgs if is_test_object_name(x.name)]
    log_deleted_objects(test_orgs, "organization")
    fixtures.tear_down_test_objects(test_orgs, )

    remove_hive_databases()