Deny chassis with too long description
Catching error at earlier stage when creating chassis with too long description that does not fit to the database table field. Change-Id: Iccd002f959d262765eb50bf4391981bdbfeec907 Closes-Bug: #1588347
This commit is contained in:
parent
a9e48a3378
commit
33ee729a08
@ -50,7 +50,7 @@ class Chassis(base.APIBase):
|
|||||||
uuid = types.uuid
|
uuid = types.uuid
|
||||||
"""The UUID of the chassis"""
|
"""The UUID of the chassis"""
|
||||||
|
|
||||||
description = wtypes.text
|
description = wtypes.StringType(max_length=255)
|
||||||
"""The description of the chassis"""
|
"""The description of the chassis"""
|
||||||
|
|
||||||
extra = {wtypes.text: types.jsontype}
|
extra = {wtypes.text: types.jsontype}
|
||||||
|
@ -43,6 +43,11 @@ class TestChassisObject(base.TestCase):
|
|||||||
chassis = api_chassis.Chassis(**chassis_dict)
|
chassis = api_chassis.Chassis(**chassis_dict)
|
||||||
self.assertEqual(wtypes.Unset, chassis.description)
|
self.assertEqual(wtypes.Unset, chassis.description)
|
||||||
|
|
||||||
|
def test_chassis_sample(self):
|
||||||
|
expected_description = 'Sample chassis'
|
||||||
|
sample = api_chassis.Chassis.sample(expand=False)
|
||||||
|
self.assertEqual(expected_description, sample.as_dict()['description'])
|
||||||
|
|
||||||
|
|
||||||
class TestListChassis(test_api_base.BaseApiTest):
|
class TestListChassis(test_api_base.BaseApiTest):
|
||||||
|
|
||||||
@ -445,6 +450,25 @@ class TestPost(test_api_base.BaseApiTest):
|
|||||||
result = self.get_json('/chassis/%s' % cdict['uuid'])
|
result = self.get_json('/chassis/%s' % cdict['uuid'])
|
||||||
self.assertEqual(descr, result['description'])
|
self.assertEqual(descr, result['description'])
|
||||||
|
|
||||||
|
def test_create_chassis_toolong_description(self):
|
||||||
|
descr = 'a' * 256
|
||||||
|
valid_error_message = ('Value should have a maximum character '
|
||||||
|
'requirement of 255')
|
||||||
|
cdict = apiutils.chassis_post_data(description=descr)
|
||||||
|
response = self.post_json('/chassis', cdict, expect_errors=True)
|
||||||
|
self.assertEqual(http_client.BAD_REQUEST, response.status_int)
|
||||||
|
self.assertEqual('application/json', response.content_type)
|
||||||
|
self.assertIn(valid_error_message, response.json['error_message'])
|
||||||
|
|
||||||
|
def test_create_chassis_invalid_description(self):
|
||||||
|
descr = 1334
|
||||||
|
valid_error_message = 'Value should be string'
|
||||||
|
cdict = apiutils.chassis_post_data(description=descr)
|
||||||
|
response = self.post_json('/chassis', cdict, expect_errors=True)
|
||||||
|
self.assertEqual(http_client.BAD_REQUEST, response.status_int)
|
||||||
|
self.assertEqual('application/json', response.content_type)
|
||||||
|
self.assertIn(valid_error_message, response.json['error_message'])
|
||||||
|
|
||||||
|
|
||||||
class TestDelete(test_api_base.BaseApiTest):
|
class TestDelete(test_api_base.BaseApiTest):
|
||||||
|
|
||||||
|
@ -0,0 +1,4 @@
|
|||||||
|
fixes:
|
||||||
|
- Deny too long description of chassis
|
||||||
|
(more than 255 chars) with appropriate
|
||||||
|
correct message.
|
Loading…
x
Reference in New Issue
Block a user