def test_terminate_instance_exception(self): formData = { 'method': 'TerminateInstance', 'instance': self.servers[0].id, } self.mox.StubOutWithMock(api, 'server_get') api.server_get(IsA(http.HttpRequest), str(self.servers[0].id)).AndReturn(self.servers[0]) exception = api_exceptions.ApiException('ApiException', message='apiException') self.mox.StubOutWithMock(api, 'server_delete') api.server_delete(IsA(http.HttpRequest), self.servers[0]).AndRaise(exception) self.mox.StubOutWithMock(messages, 'error') messages.error(IsA(http.HttpRequest), IsA(unicode)) self.mox.ReplayAll() res = self.client.post( reverse('steer:engine:instances_and_volumes:instances:index'), formData) self.assertRedirectsNoFollow( res, reverse('steer:engine:instances_and_volumes:instances:index'))
def test_create_snapshot_post_exception(self): SNAPSHOT_NAME = 'snappy' new_snapshot = self.mox.CreateMock(api.Image) new_snapshot.name = SNAPSHOT_NAME formData = { 'method': 'CreateSnapshot', 'tenant_id': self.TEST_TENANT, 'instance_id': self.good_server.id, 'name': SNAPSHOT_NAME } self.mox.StubOutWithMock(api, 'snapshot_create') exception = api_exceptions.ApiException('apiException', message='apiException') api.snapshot_create(IsA(http.HttpRequest), str(self.good_server.id), SNAPSHOT_NAME).\ AndRaise(exception) self.mox.ReplayAll() res = self.client.post( reverse('steer:engine:images_and_snapshots:snapshots:create', args=[self.good_server.id]), formData) self.assertRedirectsNoFollow( res, reverse('steer:engine:images_and_snapshots:snapshots:create', args=[self.good_server.id]))
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_usage_exception(self): now = self.override_times() exception = api_exceptions.ApiException('apiException', message='apiException') self.mox.StubOutWithMock(api, 'usage_get') api.usage_get( IsA(http.HttpRequest), self.TEST_TENANT, datetime.datetime(now.year, now.month, 1, now.hour, now.minute, now.second), now).AndRaise(exception) self.mox.StubOutWithMock(messages, 'error') messages.error(IsA(http.HttpRequest), IsA(basestring)) self.mox.ReplayAll() res = self.client.get( reverse('steer:engine:instances_and_volumes:instances:usage')) self.assertTemplateUsed( res, 'engine/instances_and_volumes/instances/usage.html') self.assertEqual(res.context['usage'], {}) self.reset_times()
def test_create_get_server_exception(self): self.mox.StubOutWithMock(api, 'server_get') exception = api_exceptions.ApiException('apiException') api.server_get(IsA(http.HttpRequest), str(self.good_server.id)).AndRaise(exception) self.mox.ReplayAll() res = self.client.get( reverse('steer:engine:images_and_snapshots:snapshots:create', args=[self.good_server.id])) self.assertRedirectsNoFollow( res, reverse('steer:engine:instances_and_volumes:instances:index'))
def test_enable_disable_user_exception(self): OTHER_USER_ID = '5' formData = {'action': 'users__enable__%s' % OTHER_USER_ID} self.mox.StubOutWithMock(api.keystone, 'user_update_enabled') api_exception = api_exceptions.ApiException('apiException', message='apiException') api.keystone.user_update_enabled(IgnoreArg(), OTHER_USER_ID, True) \ .AndRaise(api_exception) self.mox.ReplayAll() res = self.client.post(USERS_INDEX_URL, formData) self.assertRedirects(res, USERS_INDEX_URL)
def test_index_server_list_exception(self): self.mox.StubOutWithMock(api, 'server_list') self.mox.StubOutWithMock(api, 'volume_list') exception = api_exceptions.ApiException('apiException') api.server_list(IsA(http.HttpRequest)).AndRaise(exception) api.volume_list(IsA(http.HttpRequest)).AndReturn(self.volumes) self.mox.ReplayAll() res = self.client.get( reverse('steer:engine:instances_and_volumes:index')) self.assertTemplateUsed(res, 'engine/instances_and_volumes/index.html') self.assertEqual(len(res.context['instances']), 0)
def test_instance_update_get_server_get_exception(self): INSTANCE_ID = self.servers[0].id exception = api_exceptions.ApiException('apiException') self.mox.StubOutWithMock(api, 'server_get') api.server_get(IsA(http.HttpRequest), unicode(INSTANCE_ID)).AndRaise(exception) self.mox.ReplayAll() res = self.client.get( reverse('steer:engine:instances_and_volumes:instances:update', args=[INSTANCE_ID])) self.assertRedirectsNoFollow( res, reverse('steer:engine:instances_and_volumes:instances:index'))
def test_login_exception(self): form_data = { 'method': 'Login', 'password': self.PASSWORD, 'username': self.TEST_USER } self.mox.StubOutWithMock(api, 'token_create') api_exception = api_exceptions.ApiException('apiException', message='apiException') api.token_create(IsA(http.HttpRequest), "", self.TEST_USER, self.PASSWORD).AndRaise(api_exception) self.mox.ReplayAll() res = self.client.post(reverse('steer:auth_login'), form_data) self.assertTemplateUsed(res, 'splash.html')
def test_instance_vnc_exception(self): INSTANCE_ID = self.servers[0].id exception = api_exceptions.ApiException('apiException', message='apiException') self.mox.StubOutWithMock(api, 'console_create') api.console_create(IsA(http.HttpRequest), unicode(INSTANCE_ID), 'vnc').AndRaise(exception) self.mox.ReplayAll() res = self.client.get( reverse('steer:engine:instances_and_volumes:instances:vnc', args=[INSTANCE_ID])) self.assertRedirectsNoFollow( res, reverse('steer:engine:instances_and_volumes:instances:index'))
def test_reboot_instance_exception(self): formData = { 'method': 'RebootInstance', 'instance': self.servers[0].id, } self.mox.StubOutWithMock(api, 'server_reboot') exception = api_exceptions.ApiException('ApiException', message='apiException') api.server_reboot(IsA(http.HttpRequest), unicode(self.servers[0].id)).AndRaise(exception) self.mox.StubOutWithMock(messages, 'error') messages.error(IsA(http.HttpRequest), IsA(basestring)) self.mox.ReplayAll() res = self.client.post( reverse('steer:engine:instances_and_volumes:instances:index'), formData) self.assertRedirectsNoFollow( res, reverse('steer:engine:instances_and_volumes:instances:index'))