def test_instance_update_post_api_exception(self): INSTANCE_ID = self.servers[0].id NAME = 'myname' formData = {'method': 'UpdateInstance', 'instance': INSTANCE_ID, 'name': NAME, 'tenant_id': self.TEST_TENANT} self.mox.StubOutWithMock(api, 'server_get') api.server_get(IsA(http.HttpRequest), unicode(INSTANCE_ID)).AndReturn(self.servers[0]) exception = api_exceptions.ApiException('apiException') self.mox.StubOutWithMock(api, 'server_update') api.server_update(IsA(http.HttpRequest), str(INSTANCE_ID), NAME).\ AndRaise(exception) self.mox.ReplayAll() res = self.client.post( reverse('steer:engine:instances_and_volumes:instances:update', args=[INSTANCE_ID]), formData) self.assertRedirectsNoFollow(res, reverse('steer:engine:instances_and_volumes:instances:index'))
def test_instance_update_post_api_exception(self): INSTANCE_ID = self.servers[0].id NAME = 'myname' formData = { 'method': 'UpdateInstance', 'instance': INSTANCE_ID, 'name': NAME, 'tenant_id': self.TEST_TENANT } self.mox.StubOutWithMock(api, 'server_get') api.server_get(IsA(http.HttpRequest), unicode(INSTANCE_ID)).AndReturn(self.servers[0]) exception = api_exceptions.ApiException('apiException') self.mox.StubOutWithMock(api, 'server_update') api.server_update(IsA(http.HttpRequest), str(INSTANCE_ID), NAME).\ AndRaise(exception) self.mox.ReplayAll() res = self.client.post( reverse('steer:engine:instances_and_volumes:instances:update', args=[INSTANCE_ID]), formData) self.assertRedirectsNoFollow( res, reverse('steer:engine:instances_and_volumes:instances:index'))
def handle(self, request, data): tenant_id = data['tenant_id'] try: api.server_update(request, data['instance'], data['name']) messages.success(request, _("Instance '%s' updated") % data['name']) except api_exceptions.ApiException, e: messages.error(request, _('Unable to update instance: %s') % e.message)