Exemplo n.º 1
0
    def test_disable_user(self):
        OTHER_USER = "******"
        formData = {"method": "UserEnableDisableForm", "id": OTHER_USER, "enabled": "disable"}

        self.mox.StubOutWithMock(api, "user_update_enabled")
        api.user_update_enabled(IgnoreArg(), OTHER_USER, False).AndReturn(self.mox.CreateMock(api.User))

        self.mox.ReplayAll()

        res = self.client.post(USERS_INDEX_URL, formData)

        self.assertRedirectsNoFollow(res, USERS_INDEX_URL)

        self.mox.VerifyAll()
Exemplo n.º 2
0
    def test_disable_user(self):
        OTHER_USER = '******'
        formData = {'method': 'UserEnableDisableForm',
                    'id': OTHER_USER,
                    'enabled': 'disable'}

        self.mox.StubOutWithMock(api, 'user_update_enabled')
        api.user_update_enabled(IgnoreArg(), OTHER_USER, False).AndReturn(
                self.mox.CreateMock(api.User))

        self.mox.ReplayAll()

        res = self.client.post(USERS_INDEX_URL, formData)

        self.assertRedirectsNoFollow(res, USERS_INDEX_URL)
Exemplo n.º 3
0
    def test_enable_disable_user_exception(self):
        OTHER_USER = "******"
        formData = {"method": "UserEnableDisableForm", "id": OTHER_USER, "enabled": "enable"}

        self.mox.StubOutWithMock(api, "user_update_enabled")
        api_exception = api_exceptions.ApiException("apiException", message="apiException")
        api.user_update_enabled(IgnoreArg(), OTHER_USER, True).AndRaise(api_exception)

        self.mox.ReplayAll()

        res = self.client.post(USERS_INDEX_URL, formData)

        self.assertRedirectsNoFollow(res, USERS_INDEX_URL)

        self.mox.VerifyAll()
Exemplo n.º 4
0
    def handle(self, request, data):
        user_id = data["id"]
        enabled = data["enabled"] == "enable"

        try:
            api.user_update_enabled(request, user_id, enabled)
            messages.info(
                request, _("User %(user)s %(state)s") % {"user": user_id, "state": "enabled" if enabled else "disabled"}
            )
        except api_exceptions.ApiException:
            messages.error(
                request,
                _("Unable to %(state)s user %(user)s") % {"state": "enable" if enabled else "disable", "user": user_id},
            )

        return shortcuts.redirect(request.build_absolute_uri())
Exemplo n.º 5
0
    def test_disable_user(self):
        OTHER_USER = '******'
        formData = {
            'method': 'UserEnableDisableForm',
            'id': OTHER_USER,
            'enabled': 'disable'
        }

        self.mox.StubOutWithMock(api, 'user_update_enabled')
        api.user_update_enabled(IgnoreArg(), OTHER_USER,
                                False).AndReturn(self.mox.CreateMock(api.User))

        self.mox.ReplayAll()

        res = self.client.post(USERS_INDEX_URL, formData)

        self.assertRedirectsNoFollow(res, USERS_INDEX_URL)
Exemplo n.º 6
0
    def test_enable_disable_user_exception(self):
        OTHER_USER = '******'
        formData = {'method': 'UserEnableDisableForm',
                    'id': OTHER_USER,
                    'enabled': 'enable'}

        self.mox.StubOutWithMock(api, 'user_update_enabled')
        api_exception = api_exceptions.ApiException('apiException',
                message='apiException')
        api.user_update_enabled(IgnoreArg(),
                OTHER_USER, True).AndRaise(api_exception)

        self.mox.ReplayAll()

        res = self.client.post(USERS_INDEX_URL, formData)

        self.assertRedirectsNoFollow(res, USERS_INDEX_URL)
Exemplo n.º 7
0
    def test_enable_disable_user_exception(self):
        OTHER_USER = '******'
        formData = {
            'method': 'UserEnableDisableForm',
            'id': OTHER_USER,
            'enabled': 'enable'
        }

        self.mox.StubOutWithMock(api, 'user_update_enabled')
        api_exception = api_exceptions.ApiException('apiException',
                                                    message='apiException')
        api.user_update_enabled(IgnoreArg(), OTHER_USER,
                                True).AndRaise(api_exception)

        self.mox.ReplayAll()

        res = self.client.post(USERS_INDEX_URL, formData)

        self.assertRedirectsNoFollow(res, USERS_INDEX_URL)
Exemplo n.º 8
0
    def handle(self, request, data):
        user_id = data['id']
        enabled = data['enabled'] == "enable"

        try:
            api.user_update_enabled(request, user_id, enabled)
            messages.info(
                request,
                _("User %(user)s %(state)s") % {
                    "user": user_id,
                    "state": "enabled" if enabled else "disabled"
                })
        except api_exceptions.ApiException:
            messages.error(
                request,
                _("Unable to %(state)s user %(user)s") % {
                    "state": "enable" if enabled else "disable",
                    "user": user_id
                })

        return shortcuts.redirect(request.build_absolute_uri())