def test_accepting_invitation_deletes_it_from_pending_list(
            self, context, test_org):
        """
        <b>Description:</b>
        Checks if invitation is removed from pending invitations list after invitation acceptance.

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

        <b>Expected results:</b>
        Test passes when pending invitation is not present on pending invitations list after invitation acceptance.

        <b>Steps:</b>
        1. Invite new user.
        2. Register user with the received code.
        3. Check that invitation is no longer present in pending invitation list.
        """
        step("Invite new user")
        invitation = Invitation.api_send(context)
        step("Register user with the received code")
        onboarding.register(context=context,
                            org_guid=test_org.guid,
                            code=invitation.code,
                            username=invitation.username)
        step(
            "Check that invitation is no longer present in pending invitation list"
        )
        assert_not_in_with_retry(invitation, Invitation.api_get_list)
    def test_delete_pending_invitation(self, context, test_org):
        """
        <b>Description:</b>
        Checks if user cannot use obtained invitation after it was removed from pending invitations list.

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

        <b>Expected results:</b>
        Test passes when registering user fails returning HTTP status code 403 FORBIDDEN.

        <b>Steps:</b>
        1. Invite new user
        2. Delete pending user invitation.
        3. Check that the user cannot register after deletion of pending invitation.
        """
        step("Invite new user")
        invitation = Invitation.api_send(context)
        assert_in_with_retry(invitation, Invitation.api_get_list)
        step("Delete pending user invitation")
        invitation.api_delete()
        assert_not_in_with_retry(invitation, Invitation.api_get_list)
        step(
            "Check that the user cannot register after deletion of pending invitation"
        )
        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)
    def test_add_new_pending_invitation_twice_for_the_same_user(self, context):
        """
        <b>Description:</b>
        Checks if number of pending invitations is correct for a user that got 2 invitations.

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

        <b>Expected results:</b>
        Test passes when user to whom 2 invitations were sent has only 1 pending invitation on pending invitations
        list.

        <b>Steps:</b>
        1. Send invitation two times for a single user.
        2. Check that there is only one invitation for the user.
        """
        step("Send invitation two times for a single user")
        invitation = Invitation.api_send(context)
        Invitation.api_send(context, username=invitation.username)
        invited_users = [i.username for i in Invitation.api_get_list()]
        step("Check that there is only one invitation for the user")
        assert invited_users.count(
            invitation.username) == 1, "More than one invitation for the user"
    def test_add_new_pending_invitation(self, context):
        """
        <b>Description:</b>
        Checks if new pending invitations can be added.

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

        <b>Expected results:</b>
        Test passes when new pending invitation appears on pending invitations list.

        <b>Steps:</b>
        1. Invite new user.
        2. Check that the user is in the pending invitation list.
        """
        step("Invite new user")
        invitation = Invitation.api_send(context)
        step("Check that the user is in the pending invitation list")
        assert_in_with_retry(invitation, Invitation.api_get_list)
    def test_cannot_delete_pending_invitation_providing_empty_name(self):
        """
        <b>Description:</b>
        Checks if invitation cannot be removed from pending invitations list when an empty user name provided.

        <b>Input data:</b>
        1. User name.

        <b>Expected results:</b>
        Test passes when HTTP request deleting invitation returns status code 405 NOT ALLOWED.

        <b>Steps:</b>
        1. Delete invitation.
        """
        invitation = Invitation(username="")
        assert_raises_http_exception(
            HttpStatus.CODE_METHOD_NOT_ALLOWED,
            HttpStatus.MSG_METHOD_NOT_SUPPORTED.format("DELETE"),
            invitation.api_delete)
    def test_cannot_resend_invitation_providing_empty_name(self):
        """
        <b>Description:</b>
        Checks if resending emails doesn't work for invitation with empty user name.

        <b>Input data:</b>
        1. User name.

        <b>Expected results:</b>
        Test passes when HTTP request resending invitation returns status code 405 NOT ALLOWED.

        <b>Steps:</b>
        1. Resend invitation.
        """
        invitation = Invitation(username="")
        assert_raises_http_exception(
            HttpStatus.CODE_METHOD_NOT_ALLOWED,
            HttpStatus.MSG_METHOD_NOT_SUPPORTED.format("POST"),
            invitation.api_resend)
    def test_cannot_resend_not_existing_pending_invitation(self):
        """
        <b>Description:</b>
        Checks if resending emails doesn't work for not existing invitations.

        <b>Input data:</b>
        1. User name.

        <b>Expected results:</b>
        Test passes when HTTP request resending invitation returns status code 404 NOT FOUND.

        <b>Steps:</b>
        1. Resend invitation.
        """
        username = "******"
        invitation = Invitation(username=username)
        assert_raises_http_exception(
            HttpStatus.CODE_NOT_FOUND,
            HttpStatus.MSG_NO_PENDING_INVITATION_FOR.format(username),
            invitation.api_resend)
    def test_cannot_delete_not_existing_pending_invitation(self):
        """
        <b>Description:</b>
        Checks if not existing invitation cannot be removed from pending invitations list.

        <b>Input data:</b>
        1. User name.

        <b>Expected results:</b>
        Test passes when HTTP request deleting invitation returns status code 404 NOT FOUND.

        <b>Steps:</b>
        1. Try to delete not existing invitation.
        """
        step("Try to delete not existing invitation")
        username = "******"
        invitation = Invitation(username=username)
        assert_raises_http_exception(
            HttpStatus.CODE_NOT_FOUND,
            HttpStatus.MSG_NO_PENDING_INVITATION_FOR.format(username),
            invitation.api_delete)
Beispiel #9
0
    def test_use_invitation_after_pod_restart(self, context, test_org):
        """
        <b>Description:</b>
        Checks if user invitation is valid after user-management POD restart.

        <b>Input data:</b>
        1. User name.
        2. Password.

        <b>Expected results:</b>
        Test passes when user was correctly added to the platform.

        <b>Steps:</b>
        1. Invite new user.
        2. Retrieve user-management POD
        2. Restart user-management POD, verify health.
        3. Register user with the invitation.
        """

        step("Invite new user")
        invitation = Invitation.api_send(context)

        step("Retrieve user-management pod")
        pods_list = KubernetesPod.get_list()
        user_mngt_pod = next((pod for pod in pods_list
                              if pod.name.startswith(self.POD_NAME_PREFIX)),
                             None)
        assert user_mngt_pod is not None, \
            "POD {} wasn't found on the PODs list".format(self.POD_NAME_PREFIX)

        step("Restart user-management POD, verify health")
        user_mngt_pod.restart_pod()
        user_mngt_pod.ensure_pod_in_good_health()

        step("Register user with the invitation")
        user = onboarding.register(context=context,
                                   org_guid=test_org.guid,
                                   code=invitation.code,
                                   username=invitation.username)
        assert_user_in_org_and_role(user, test_org.guid, User.ORG_ROLE["user"])
    def test_resend_pending_invitation(self, context, test_org):
        """
        <b>Description:</b>
        Checks if resending emails works.

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

        <b>Expected results:</b>
        Test passes when user obtained email with invitation and second email with invitation after it's resent.

        <b>Steps:</b>
        1. Invite new user.
        2. Check that the user received the message.
        3. Resend invitation.
        4. Check that the user received the new message.
        5. Register user with the received code.
        """
        step("Invite new user")
        invitation = Invitation.api_send(context)
        step("Check that the user received the message")
        messages = gmail_api.wait_for_messages_to(
            recipient=invitation.username, messages_number=1)
        assert len(messages) == 1
        step("Resend invitation")
        invitation.api_resend()
        step("Check that the user received the new message")
        messages = gmail_api.wait_for_messages_to(
            recipient=invitation.username, messages_number=2)
        assert len(messages) == 2
        step("Register user with the received code")
        user = onboarding.register(context=context,
                                   org_guid=test_org.guid,
                                   code=invitation.code,
                                   username=invitation.username)
        assert_user_in_org_and_role(user, test_org.guid, User.ORG_ROLE["user"])