]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Add unit tests for cinder/api/contrib/volume_actions.
authorJasakov Artem <ayasakov@mirantis.com>
Fri, 5 Jul 2013 07:59:56 +0000 (11:59 +0400)
committerJasakov Artem <ayasakov@mirantis.com>
Fri, 5 Jul 2013 07:59:56 +0000 (11:59 +0400)
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

cinder/tests/api/contrib/test_volume_actions.py

index 623148392c31355a401120ceb8d6acad5ce7f74a..1720a8ccdf316c77eb4bbfe8c396f228ff81c624 100644 (file)
@@ -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)