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()
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)
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()
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())
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)
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)
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)
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())