Merge "Check that region ID is not an empty string"

This commit is contained in:
Jenkins 2014-08-01 23:37:51 +00:00 committed by Gerrit Code Review
commit 76f3c55e71
2 changed files with 12 additions and 1 deletions

View File

@ -193,7 +193,7 @@ class RegionV3(controller.V3Controller):
def create_region(self, context, region):
ref = self._normalize_dict(region)
if 'id' not in ref:
if not ref.get('id'):
ref = self._assign_unique_id(ref)
ref = self.catalog_api.create_region(ref)

View File

@ -115,6 +115,17 @@ class CatalogTestCase(test_v3.RestfulTestCase):
'region_id': ref['id']})
self.assertValidRegionResponse(r, ref)
def test_create_region_with_empty_id(self):
"""Call ``POST /regions`` with an empty ID in the request body."""
ref = self.new_region_ref()
ref['id'] = ''
r = self.post(
'/regions',
body={'region': ref}, expected_status=201)
self.assertValidRegionResponse(r, ref)
self.assertNotEmpty(r.result['region'].get('id'))
def test_create_region_without_id(self):
"""Call ``POST /regions`` without an ID in the request body."""
ref = self.new_region_ref()