add missing parent_id parameter check in project schema

Closes-Bug: #1410182
Change-Id: Ib684bd870a995e482d7c1a91f0acb5f4bfd96a57
This commit is contained in:
wanghong 2015-01-13 16:15:06 +08:00
parent a22aa08bf2
commit cd4d7fdca0
2 changed files with 24 additions and 0 deletions

View File

@ -21,6 +21,7 @@ _project_properties = {
# implementation.
'domain_id': parameter_types.id_string,
'enabled': parameter_types.boolean,
'parent_id': validation.nullable(parameter_types.id_string),
'name': {
'type': 'string',
'minLength': 1,

View File

@ -360,6 +360,29 @@ class ProjectValidationTestCase(testtools.TestCase):
self.create_project_validator.validate,
request_to_validate)
def test_validate_project_request_with_valid_parent_id(self):
"""Test that we validate `parent_id` in create project requests."""
# parent_id is nullable
request_to_validate = {'name': self.project_name,
'parent_id': None}
self.create_project_validator.validate(request_to_validate)
request_to_validate = {'name': self.project_name,
'parent_id': uuid.uuid4().hex}
self.create_project_validator.validate(request_to_validate)
def test_validate_project_request_with_invalid_parent_id_fails(self):
"""Exception is raised when `parent_id` as a non-id value."""
request_to_validate = {'name': self.project_name,
'parent_id': False}
self.assertRaises(exception.SchemaValidationError,
self.create_project_validator.validate,
request_to_validate)
request_to_validate = {'name': self.project_name,
'parent_id': 'fake project'}
self.assertRaises(exception.SchemaValidationError,
self.create_project_validator.validate,
request_to_validate)
def test_validate_project_update_request(self):
"""Test that we validate a project update request."""
request_to_validate = {'domain_id': uuid.uuid4().hex}