Exemplo n.º 1
0
    def test_delete_enterprise_admin_role_assignment_success(
            self,
            mock_create_tableau_user,  # pylint: disable=unused-argument
    ):
        """
        Test that when `EnterpriseCustomerUser` record is deleted, the associated
        enterprise admin user role assignment is also deleted.
        """
        # create new PendingEnterpriseCustomerAdminUser and EnterpriseCustomerUser records.
        PendingEnterpriseCustomerAdminUserFactory(
            user_email=self.admin_user.email,
            enterprise_customer=self.enterprise_customer,
        )
        EnterpriseCustomerUserFactory(
            user_id=self.admin_user.id,
            enterprise_customer=self.enterprise_customer,
        )

        # verify that a new admin role assignment is created.
        admin_role_assignments = SystemWideEnterpriseUserRoleAssignment.objects.filter(
            user=self.admin_user,
            role=self.enterprise_admin_role,
        )
        self.assertTrue(admin_role_assignments.exists())

        # delete EnterpriseCustomerUser record and verify that admin role assignment is deleted as well.
        EnterpriseCustomerUser.objects.filter(user_id=self.admin_user.id).delete()
        admin_role_assignments = SystemWideEnterpriseUserRoleAssignment.objects.filter(
            user=self.admin_user,
            role=self.enterprise_admin_role,
        )
        self.assertFalse(admin_role_assignments.exists())
Exemplo n.º 2
0
    def test_create_tableau_user_success(self, mock_create_tableau_user, has_pending_admin_user):
        """
        Test that when a new `EnterpriseCustomerUser` record is created, a tableau user is also created,
        assuming a `PendingEnterpriseCustomerAdminUser` record exists.
        """
        if has_pending_admin_user:
            PendingEnterpriseCustomerAdminUserFactory(
                user_email=self.admin_user.email,
                enterprise_customer=self.enterprise_customer,
            )
        # verify that no EnterpriseCustomerUser exists.
        enterprise_customer_user = EnterpriseCustomerUser.objects.filter(
            user_id=self.admin_user.id,
        )
        self.assertFalse(enterprise_customer_user.exists())

        # create a new EnterpriseCustomerUser record.
        EnterpriseCustomerUserFactory(
            user_id=self.admin_user.id,
            enterprise_customer=self.enterprise_customer,
        )
        if has_pending_admin_user:
            mock_create_tableau_user.assert_called_once()
        else:
            mock_create_tableau_user.assert_not_called()
Exemplo n.º 3
0
    def test_handle_user_post_save_with_pending_enterprise_admin(self, mock_create_tableau_user):
        email = "*****@*****.**"
        user = UserFactory(id=1, email=email)
        enterprise_customer = EnterpriseCustomerFactory()
        PendingEnterpriseCustomerAdminUserFactory(enterprise_customer=enterprise_customer, user_email=email)

        assert PendingEnterpriseCustomerAdminUser.objects.filter(user_email=email).count() == 1, \
            "Precondition check: pending admin user exists"

        parameters = {"instance": user, "created": False}
        handle_user_post_save(mock.Mock(), **parameters)

        assert EnterpriseCustomerUser.objects.filter(user_id=user.id).count() == 1, \
            "Precondition check: enterprise customer user exists"

        enterprise_customer_user = EnterpriseCustomerUser.objects.get(user_id=user.id)

        enterprise_admin_role, __ = SystemWideEnterpriseRole.objects.get_or_create(name=ENTERPRISE_ADMIN_ROLE)
        admin_role_assignment = SystemWideEnterpriseUserRoleAssignment.objects.filter(
            user=user,
            role=enterprise_admin_role,
        )
        assert admin_role_assignment.exists()

        mock_create_tableau_user.assert_called_once_with(
            str(enterprise_customer.uuid).replace('-', ''),
            enterprise_customer_user,
        )

        assert PendingEnterpriseCustomerAdminUser.objects.filter(user_email=email).count() == 0, \
            "Final check: pending admin user no longer exists"
Exemplo n.º 4
0
    def test_create_pending_enterprise_admin_user(self):
        """
        Assert that creating a ``PendingEnterpriseCustomerAdminUser`` creates a ``PendingEnterpriseCustomerUser``.
        """
        # verify that PendingEnterpriseCustomerUser record does not yet exist.
        self._assert_pending_ecus_exist(should_exist=False)

        # create new PendingEnterpriseCustomerAdminUser
        PendingEnterpriseCustomerAdminUserFactory(
            user_email=self.admin_user.email,
            enterprise_customer=self.enterprise_customer,
        )

        # verify that PendingEnterpriseCustomerUser record was created.
        self._assert_pending_ecus_exist()
Exemplo n.º 5
0
    def test_assign_enterprise_admin_role_post_save(
            self,
            mock_create_tableau_user,  # pylint: disable=unused-argument
            should_unlink_user,
            should_admin_role_exist
    ):
        """
        Verify that the enterprise_admin role is created on update.
        When the EnterpriseCustomerUser record is unlinked, the role should be removed.
        """
        # create new PendingEnterpriseCustomerAdminUser and EnterpriseCustomerUser records.
        PendingEnterpriseCustomerAdminUserFactory(
            user_email=self.admin_user.email,
            enterprise_customer=self.enterprise_customer,
        )
        EnterpriseCustomerUserFactory(
            user_id=self.admin_user.id,
            enterprise_customer=self.enterprise_customer,
        )

        # update EnterpriseCustomerUser record.
        enterprise_customer_user = EnterpriseCustomerUser.objects.get(
            user_id=self.admin_user.id
        )
        if should_unlink_user:
            enterprise_customer_user.linked = False
        else:
            enterprise_customer_user.active = False
        enterprise_customer_user.save()

        if should_admin_role_exist:
            # verify that the enterprise_admin role exists.
            admin_role_assignments = SystemWideEnterpriseUserRoleAssignment.objects.filter(
                user=self.admin_user,
                role=self.enterprise_admin_role,
            )
            self.assertTrue(admin_role_assignments.exists())
        else:
            # verify that the enterprise_admin role is deleted when unlinking an EnterpriseCustomerUser
            admin_role_assignments = SystemWideEnterpriseUserRoleAssignment.objects.filter(
                user=self.admin_user,
                role=self.enterprise_admin_role,
            )
            self.assertFalse(admin_role_assignments.exists())
Exemplo n.º 6
0
    def test_delete_pending_enterprise_admin_user(self):
        """
        Assert that deleting a ``PendingEnterpriseCustomerAdminUser`` deletes its ``PendingEnterpriseCustomerUser``.
        """
        # create new PendingEnterpriseCustomerAdminUser
        PendingEnterpriseCustomerAdminUserFactory(
            user_email=self.admin_user.email,
            enterprise_customer=self.enterprise_customer,
        )

        # verify that PendingEnterpriseCustomerUser record exists.
        self._assert_pending_ecus_exist()

        # delete the PendingEnterpriseCustomerAdminUser record and verify that the
        # associated PendingEnterpriseCustomerUser is also deleted.
        PendingEnterpriseCustomerAdminUser.objects.filter(
            user_email=self.admin_user.email,
            enterprise_customer=self.enterprise_customer,
        ).delete()
        self._assert_pending_ecus_exist(should_exist=False)
Exemplo n.º 7
0
    def test_assign_enterprise_admin_role_success(
            self,
            mock_create_tableau_user,  # pylint: disable=unused-argument
            has_pending_admin_user
    ):
        """
        Test that when a new `EnterpriseCustomerUser` record is created, an enterprise admin role is created for
        that user, assuming a `PendingEnterpriseCustomerAdminUser` record exists.
        """
        if has_pending_admin_user:
            PendingEnterpriseCustomerAdminUserFactory(
                user_email=self.admin_user.email,
                enterprise_customer=self.enterprise_customer,
            )
        # verify that no EnterpriseCustomerUser exists.
        enterprise_customer_user = EnterpriseCustomerUser.objects.filter(
            user_id=self.admin_user.id,
        )
        self.assertFalse(enterprise_customer_user.exists())

        # verify that no admin role assignment exists.
        admin_role_assignment = SystemWideEnterpriseUserRoleAssignment.objects.filter(
            user=self.admin_user,
            role=self.enterprise_admin_role,
        )
        self.assertFalse(admin_role_assignment.exists())

        # create a new EnterpriseCustomerUser record.
        EnterpriseCustomerUserFactory(
            user_id=self.admin_user.id,
            enterprise_customer=self.enterprise_customer,
        )

        # verify that a new admin user role assignment is created when appropriate.
        admin_role_assignment = SystemWideEnterpriseUserRoleAssignment.objects.filter(
            user=self.admin_user,
            role=self.enterprise_admin_role,
        )
        assert admin_role_assignment.exists() == has_pending_admin_user