diff --git a/nailgun/nailgun/api/v1/validators/json_schema/assignment.py b/nailgun/nailgun/api/v1/validators/json_schema/assignment.py index e487bef94d..daa265dd9b 100644 --- a/nailgun/nailgun/api/v1/validators/json_schema/assignment.py +++ b/nailgun/nailgun/api/v1/validators/json_schema/assignment.py @@ -31,7 +31,8 @@ assignment_format_schema = { 'type': 'array', 'items': {'type': 'string'} } - } + }, + 'required': ['id', 'roles'], } } diff --git a/nailgun/nailgun/test/unit/test_assignment_validator.py b/nailgun/nailgun/test/unit/test_assignment_validator.py index efd215752e..cf32c13fe9 100644 --- a/nailgun/nailgun/test/unit/test_assignment_validator.py +++ b/nailgun/nailgun/test/unit/test_assignment_validator.py @@ -17,7 +17,10 @@ from nailgun.errors import errors from nailgun.test.base import BaseUnitTest -class TestAssignmentValidator(BaseUnitTest): +class TestNodeAssignmentValidator(BaseUnitTest): + + validator = NodeAssignmentValidator + def setUp(self): self.models = { 'settings': { @@ -29,7 +32,7 @@ class TestAssignmentValidator(BaseUnitTest): } } - def test_check_roles_requirement(self): + def test_check_roles_requirement_equal(self): roles = ['test'] roles_metadata = { 'test': { @@ -42,10 +45,10 @@ class TestAssignmentValidator(BaseUnitTest): } } - NodeAssignmentValidator.check_roles_requirement(roles, - roles_metadata, - self.models) + self.validator.check_roles_requirement( + roles, roles_metadata, self.models) + def test_check_roles_requirement_not_equal(self): roles = ['test'] roles_metadata = { 'test': { @@ -58,9 +61,8 @@ class TestAssignmentValidator(BaseUnitTest): } } - NodeAssignmentValidator.check_roles_requirement(roles, - roles_metadata, - self.models) + self.validator.check_roles_requirement( + roles, roles_metadata, self.models) def test_check_roles_requirement_failed(self): roles = ['test'] @@ -78,6 +80,21 @@ class TestAssignmentValidator(BaseUnitTest): } } - NodeAssignmentValidator.check_roles_requirement(roles, - roles_metadata, - self.models) + self.validator.check_roles_requirement( + roles, roles_metadata, self.models) + + def test_validate_collection_update_schema_requirements(self): + self.assertRaises( + errors.InvalidData, + self.validator.validate_collection_update, + '[{}]') + + self.assertRaises( + errors.InvalidData, + self.validator.validate_collection_update, + '[{"id": 1}]') + + self.assertRaises( + errors.InvalidData, + self.validator.validate_collection_update, + '[{"roles": []}]')