Merge "Add API unit tests for snapshot creation force values"

This commit is contained in:
Jenkins 2016-11-07 00:14:23 +00:00 committed by Gerrit Code Review
commit 6c55a26096
2 changed files with 64 additions and 7 deletions

View File

@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import ddt
import mock
import webob
@ -74,6 +75,7 @@ def stub_snapshot_get_all(self, context, search_opts=None):
return [param]
@ddt.ddt
class SnapshotApiTest(test.TestCase):
def setUp(self):
super(SnapshotApiTest, self).setUp()
@ -101,13 +103,14 @@ class SnapshotApiTest(test.TestCase):
self.assertEqual(snapshot['display_description'],
resp_dict['snapshot']['display_description'])
def test_snapshot_create_force(self):
@ddt.data(True, 'y', 'true', 'trUE', 'yes', '1', 1)
def test_snapshot_create_force(self, force_param):
self.stubs.Set(volume.api.API,
"create_snapshot_force",
stub_snapshot_create)
self.stubs.Set(volume.api.API, 'get', stubs.stub_volume_get)
snapshot = {"volume_id": fake.VOLUME_ID,
"force": True,
"force": force_param,
"display_name": "Snapshot Test Name",
"display_description": "Snapshot Test Desc"}
body = dict(snapshot=snapshot)
@ -120,6 +123,29 @@ class SnapshotApiTest(test.TestCase):
self.assertEqual(snapshot['display_description'],
resp_dict['snapshot']['display_description'])
@ddt.data(False, 'n', 'false', 'falSE', 'No', '0', 0)
def test_snapshot_create_force_failure(self, force_param):
self.stubs.Set(volume.api.API,
"create_snapshot_force",
stub_snapshot_create)
self.stubs.Set(volume.api.API, 'get', stubs.stub_volume_get)
snapshot = {"volume_id": fake.VOLUME_ID,
"force": force_param,
"display_name": "Snapshot Test Name",
"display_description": "Snapshot Test Desc"}
body = dict(snapshot=snapshot)
req = fakes.HTTPRequest.blank('/v1/snapshots')
self.assertRaises(exception.InvalidVolume,
self.controller.create,
req,
body)
@ddt.data("**&&^^%%$$##@@", '-1', 2, '01', 'on', 'off', "1 ")
def test_snapshot_create_invalid_force_param(self, force_param):
self.stubs.Set(volume.api.API,
"create_snapshot_force",
stub_snapshot_create)
self.stubs.Set(volume.api.API, 'get', stubs.stub_volume_get)
snapshot = {"volume_id": fake.SNAPSHOT_ID,
"force": "**&&^^%%$$##@@",
"display_name": "Snapshot Test Name",

View File

@ -13,6 +13,7 @@
# License for the specific language governing permissions and limitations
# under the License.
import ddt
import mock
from oslo_config import cfg
from six.moves.urllib import parse as urllib
@ -76,6 +77,7 @@ def fake_snapshot_get_all(self, context, search_opts=None):
return [param]
@ddt.ddt
class SnapshotApiTest(test.TestCase):
def setUp(self):
super(SnapshotApiTest, self).setUp()
@ -107,13 +109,14 @@ class SnapshotApiTest(test.TestCase):
self.assertIn('updated_at', resp_dict['snapshot'])
db.volume_destroy(self.ctx, volume.id)
def test_snapshot_create_force(self):
@ddt.data(True, 'y', 'true', 'trUE', 'yes', '1', 'on', 1, "1 ")
def test_snapshot_create_force(self, force_param):
volume = utils.create_volume(self.ctx, status='in-use')
snapshot_name = 'Snapshot Test Name'
snapshot_description = 'Snapshot Test Desc'
snapshot = {
"volume_id": volume.id,
"force": True,
"force": force_param,
"name": snapshot_name,
"description": snapshot_description
}
@ -128,11 +131,39 @@ class SnapshotApiTest(test.TestCase):
resp_dict['snapshot']['description'])
self.assertIn('updated_at', resp_dict['snapshot'])
db.volume_destroy(self.ctx, volume.id)
@ddt.data(False, 'n', 'false', 'falSE', 'No', '0', 'off', 0)
def test_snapshot_create_force_failure(self, force_param):
volume = utils.create_volume(self.ctx, status='in-use')
snapshot_name = 'Snapshot Test Name'
snapshot_description = 'Snapshot Test Desc'
snapshot = {
"volume_id": volume.id,
"force": "**&&^^%%$$##@@",
"name": "Snapshot Test Name",
"description": "Snapshot Test Desc"
"force": force_param,
"name": snapshot_name,
"description": snapshot_description
}
body = dict(snapshot=snapshot)
req = fakes.HTTPRequest.blank('/v2/snapshots')
self.assertRaises(exception.InvalidVolume,
self.controller.create,
req,
body)
db.volume_destroy(self.ctx, volume.id)
@ddt.data("**&&^^%%$$##@@", '-1', 2, '01')
def test_snapshot_create_invalid_force_param(self, force_param):
volume = utils.create_volume(self.ctx, status='in-use')
snapshot_name = 'Snapshot Test Name'
snapshot_description = 'Snapshot Test Desc'
snapshot = {
"volume_id": volume.id,
"force": force_param,
"name": snapshot_name,
"description": snapshot_description
}
body = dict(snapshot=snapshot)
req = fakes.HTTPRequest.blank('/v2/snapshots')