From: Jasakov Artem Date: Fri, 5 Jul 2013 07:59:56 +0000 (+0400) Subject: Add unit tests for cinder/api/contrib/volume_actions. X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=6ed3990d6aa8450e9b246d0e02724cf133b9059c;p=openstack-build%2Fcinder-build.git Add unit tests for cinder/api/contrib/volume_actions. Added to the following unit tests: Test begin detaching; Test roll detaching; Test volume upload to image with TypeError; Test extend volume with ValueError; Test copy volume to image, when body without Image's name. Change-Id: I2382e043b7968a2c285c505ec02ff65fd81ea605 --- diff --git a/cinder/tests/api/contrib/test_volume_actions.py b/cinder/tests/api/contrib/test_volume_actions.py index 623148392..1720a8ccd 100644 --- a/cinder/tests/api/contrib/test_volume_actions.py +++ b/cinder/tests/api/contrib/test_volume_actions.py @@ -136,6 +136,36 @@ class VolumeActionsTest(test.TestCase): res = req.get_response(fakes.wsgi_app()) self.assertEqual(res.status_int, 400) + def test_begin_detaching(self): + def fake_begin_detaching(*args, **kwargs): + return {} + self.stubs.Set(volume.API, 'begin_detaching', + fake_begin_detaching) + + body = {'os-begin_detaching': {'fake': 'fake'}} + req = webob.Request.blank('/v2/fake/volumes/1/action') + req.method = "POST" + req.body = jsonutils.dumps(body) + req.headers["content-type"] = "application/json" + + res = req.get_response(fakes.wsgi_app()) + self.assertEqual(res.status_int, 202) + + def test_roll_detaching(self): + def fake_roll_detaching(*args, **kwargs): + return {} + self.stubs.Set(volume.API, 'roll_detaching', + fake_roll_detaching) + + body = {'os-roll_detaching': {'fake': 'fake'}} + req = webob.Request.blank('/v2/fake/volumes/1/action') + req.method = "POST" + req.body = jsonutils.dumps(body) + req.headers["content-type"] = "application/json" + + res = req.get_response(fakes.wsgi_app()) + self.assertEqual(res.status_int, 202) + def test_extend_volume(self): def fake_extend_volume(*args, **kwargs): return {} @@ -289,3 +319,36 @@ class VolumeImageActionsTest(test.TestCase): req, id, body) + + def test_volume_upload_image_typeerror(self): + body = {"os-volume_upload_image_fake": "fake"} + req = fakes.HTTPRequest.blank('/v2/tenant1/volumes/%s/action' % id) + self.assertRaises(webob.exc.HTTPBadRequest, + self.controller._volume_upload_image, + req, + id, + body) + + def test_extend_volume_valueerror(self): + id = 1 + body = {'os-extend': {'new_size': 'fake'}} + req = fakes.HTTPRequest.blank('/v2/tenant1/volumes/%s/action' % id) + self.assertRaises(webob.exc.HTTPBadRequest, + self.controller._extend, + req, + id, + body) + + def test_copy_volume_to_image_notimagename(self): + id = 1 + vol = {"container_format": 'bare', + "disk_format": 'raw', + "image_name": None, + "force": True} + body = {"os-volume_upload_image": vol} + req = fakes.HTTPRequest.blank('/v2/tenant1/volumes/%s/action' % id) + self.assertRaises(webob.exc.HTTPBadRequest, + self.controller._volume_upload_image, + req, + id, + body)