Functional test for flavor validation in bay creation

Add a negative functional test case to validate bay's flavor.

Change-Id: I5d59f32f76e974054f69f46ffeabea5cd280288c
Closes-Bug: #1520353
This commit is contained in:
houming-wang 2016-01-14 17:11:35 +08:00
parent ba0bcf20e3
commit eeb28dc9ec
2 changed files with 40 additions and 0 deletions

View File

@ -169,6 +169,31 @@ class BayTest(base.BaseMagnumTest):
exceptions.BadRequest,
self.bay_client.post_bay, gen_model)
@testtools.testcase.attr('negative')
def test_create_bay_with_nonexisting_flavor(self):
gen_model = datagen.baymodel_data_with_valid_keypair_image_flavor()
resp, baymodel = self._create_baymodel(gen_model)
self.assertEqual(resp.status, 201)
self.assertIsNotNone(baymodel.uuid)
patch_model = datagen.baymodel_flavor_patch_data()
resp, new_model = self.baymodel_client.patch_baymodel(
baymodel.uuid, patch_model)
self.assertEqual(200, resp.status)
resp, model = self.baymodel_client.get_baymodel(new_model.uuid)
self.assertEqual(200, resp.status)
self.assertEqual(baymodel.uuid, new_model.uuid)
self.assertEqual(model.flavor_id, new_model.flavor_id)
gen_model = datagen.valid_bay_data(baymodel_id=baymodel.uuid)
self.assertRaises(
exceptions.BadRequest,
self.bay_client.post_bay, gen_model)
resp, _ = self._delete_baymodel(baymodel.uuid)
self.assertEqual(resp.status, 204)
@testtools.testcase.attr('negative')
def test_update_bay_for_nonexisting_bay(self):
patch_model = datagen.bay_name_patch_data()

View File

@ -136,6 +136,21 @@ def baymodel_name_patch_data(name=data_utils.rand_name('bay')):
return baymodelpatch_model.BayModelPatchCollection.from_dict(data)
def baymodel_flavor_patch_data(flavor=data_utils.rand_name('bay')):
"""Generates random baymodel patch data
:param flavor: flavor to replace in patch
:returns: BayModelPatchCollection with generated data
"""
data = [{
"path": "/flavor_id",
"value": flavor,
"op": "replace"
}]
return baymodelpatch_model.BayModelPatchCollection.from_dict(data)
def baymodel_data_with_valid_keypair_image_flavor():
"""Generates random baymodel data with valid keypair,image and flavor