Merge "Concentrated test_validate_xx_configuration to a new method"
This commit is contained in:
commit
7c405f3d39
@ -53,6 +53,19 @@ class TestConfigurationController(trove_testtools.TestCase):
|
|||||||
super(TestConfigurationController, self).setUp()
|
super(TestConfigurationController, self).setUp()
|
||||||
self.controller = ConfigurationsController()
|
self.controller = ConfigurationsController()
|
||||||
|
|
||||||
|
def _test_validate_configuration_with_action(self, body, action,
|
||||||
|
is_valid=True):
|
||||||
|
schema = self.controller.get_schema(action, body)
|
||||||
|
self.assertIsNotNone(schema)
|
||||||
|
validator = jsonschema.Draft4Validator(schema)
|
||||||
|
if is_valid:
|
||||||
|
self.assertTrue(validator.is_valid(body))
|
||||||
|
else:
|
||||||
|
self.assertFalse(validator.is_valid(body))
|
||||||
|
errors = sorted(validator.iter_errors(body), key=lambda e: e.path)
|
||||||
|
error_messages = [error.message for error in errors]
|
||||||
|
return error_messages
|
||||||
|
|
||||||
def test_validate_create_configuration(self):
|
def test_validate_create_configuration(self):
|
||||||
body = {
|
body = {
|
||||||
"configuration": {
|
"configuration": {
|
||||||
@ -64,10 +77,7 @@ class TestConfigurationController(trove_testtools.TestCase):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
schema = self.controller.get_schema('create', body)
|
self._test_validate_configuration_with_action(body, action='create')
|
||||||
self.assertIsNotNone(schema)
|
|
||||||
validator = jsonschema.Draft4Validator(schema)
|
|
||||||
self.assertTrue(validator.is_valid(body))
|
|
||||||
|
|
||||||
def test_validate_create_configuration_no_datastore(self):
|
def test_validate_create_configuration_no_datastore(self):
|
||||||
body = {
|
body = {
|
||||||
@ -76,10 +86,7 @@ class TestConfigurationController(trove_testtools.TestCase):
|
|||||||
"name": "test"
|
"name": "test"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
schema = self.controller.get_schema('create', body)
|
self._test_validate_configuration_with_action(body, action='create')
|
||||||
self.assertIsNotNone(schema)
|
|
||||||
validator = jsonschema.Draft4Validator(schema)
|
|
||||||
self.assertTrue(validator.is_valid(body))
|
|
||||||
|
|
||||||
def test_validate_create_invalid_values_param(self):
|
def test_validate_create_invalid_values_param(self):
|
||||||
body = {
|
body = {
|
||||||
@ -92,12 +99,10 @@ class TestConfigurationController(trove_testtools.TestCase):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
schema = self.controller.get_schema('create', body)
|
error_messages = (
|
||||||
self.assertIsNotNone(schema)
|
self._test_validate_configuration_with_action(body,
|
||||||
validator = jsonschema.Draft4Validator(schema)
|
action='create',
|
||||||
self.assertFalse(validator.is_valid(body))
|
is_valid=False))
|
||||||
errors = sorted(validator.iter_errors(body), key=lambda e: e.path)
|
|
||||||
error_messages = [error.message for error in errors]
|
|
||||||
self.assertIn("'' is not of type 'object'", error_messages)
|
self.assertIn("'' is not of type 'object'", error_messages)
|
||||||
|
|
||||||
def test_validate_create_invalid_name_param(self):
|
def test_validate_create_invalid_name_param(self):
|
||||||
@ -111,12 +116,10 @@ class TestConfigurationController(trove_testtools.TestCase):
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
schema = self.controller.get_schema('create', body)
|
error_messages = (
|
||||||
self.assertIsNotNone(schema)
|
self._test_validate_configuration_with_action(body,
|
||||||
validator = jsonschema.Draft4Validator(schema)
|
action='create',
|
||||||
self.assertFalse(validator.is_valid(body))
|
is_valid=False))
|
||||||
errors = sorted(validator.iter_errors(body), key=lambda e: e.path)
|
|
||||||
error_messages = [error.message for error in errors]
|
|
||||||
self.assertIn("'' is too short", error_messages)
|
self.assertIn("'' is too short", error_messages)
|
||||||
|
|
||||||
def test_validate_edit_configuration(self):
|
def test_validate_edit_configuration(self):
|
||||||
@ -125,10 +128,7 @@ class TestConfigurationController(trove_testtools.TestCase):
|
|||||||
"values": {}
|
"values": {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
schema = self.controller.get_schema('edit', body)
|
self._test_validate_configuration_with_action(body, action="edit")
|
||||||
self.assertIsNotNone(schema)
|
|
||||||
validator = jsonschema.Draft4Validator(schema)
|
|
||||||
self.assertTrue(validator.is_valid(body))
|
|
||||||
|
|
||||||
def _test_validate_configuration(self, input_values, config_rules=None):
|
def _test_validate_configuration(self, input_values, config_rules=None):
|
||||||
if config_rules is None:
|
if config_rules is None:
|
||||||
@ -186,6 +186,19 @@ class TestConfigurationsParameterController(trove_testtools.TestCase):
|
|||||||
super(TestConfigurationsParameterController, self).setUp()
|
super(TestConfigurationsParameterController, self).setUp()
|
||||||
self.controller = service.ConfigurationsParameterController()
|
self.controller = service.ConfigurationsParameterController()
|
||||||
|
|
||||||
|
def _test_validate_configuration_with_action(self, body, action,
|
||||||
|
is_valid=True):
|
||||||
|
schema = self.controller.get_schema(action, body)
|
||||||
|
self.assertIsNotNone(schema)
|
||||||
|
validator = jsonschema.Draft4Validator(schema)
|
||||||
|
if is_valid:
|
||||||
|
self.assertTrue(validator.is_valid(body))
|
||||||
|
else:
|
||||||
|
self.assertFalse(validator.is_valid(body))
|
||||||
|
errors = sorted(validator.iter_errors(body), key=lambda e: e.path)
|
||||||
|
error_messages = [error.message for error in errors]
|
||||||
|
return error_messages
|
||||||
|
|
||||||
def test_validate_create_configuration_param(self):
|
def test_validate_create_configuration_param(self):
|
||||||
body = {
|
body = {
|
||||||
'configuration-parameter': {
|
'configuration-parameter': {
|
||||||
@ -196,10 +209,8 @@ class TestConfigurationsParameterController(trove_testtools.TestCase):
|
|||||||
'max': '255'
|
'max': '255'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
schema = self.controller.get_schema('create', body)
|
|
||||||
self.assertIsNotNone(schema)
|
self._test_validate_configuration_with_action(body, action='create')
|
||||||
validator = jsonschema.Draft4Validator(schema)
|
|
||||||
self.assertTrue(validator.is_valid(body))
|
|
||||||
|
|
||||||
def test_validate_create_invalid_restart_required(self):
|
def test_validate_create_invalid_restart_required(self):
|
||||||
body = {
|
body = {
|
||||||
@ -211,12 +222,10 @@ class TestConfigurationsParameterController(trove_testtools.TestCase):
|
|||||||
'max': 255
|
'max': 255
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
schema = self.controller.get_schema('create', body)
|
error_messages = (
|
||||||
self.assertIsNotNone(schema)
|
self._test_validate_configuration_with_action(body,
|
||||||
validator = jsonschema.Draft4Validator(schema)
|
action='create',
|
||||||
self.assertFalse(validator.is_valid(body))
|
is_valid=False))
|
||||||
errors = sorted(validator.iter_errors(body), key=lambda e: e.path)
|
|
||||||
error_messages = [error.message for error in errors]
|
|
||||||
self.assertIn("5 is greater than the maximum of 1", error_messages)
|
self.assertIn("5 is greater than the maximum of 1", error_messages)
|
||||||
self.assertIn("0 is not of type 'string'", error_messages)
|
self.assertIn("0 is not of type 'string'", error_messages)
|
||||||
self.assertIn("255 is not of type 'string'", error_messages)
|
self.assertIn("255 is not of type 'string'", error_messages)
|
||||||
@ -231,12 +240,10 @@ class TestConfigurationsParameterController(trove_testtools.TestCase):
|
|||||||
'max': '255'
|
'max': '255'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
schema = self.controller.get_schema('create', body)
|
error_messages = (
|
||||||
self.assertIsNotNone(schema)
|
self._test_validate_configuration_with_action(body,
|
||||||
validator = jsonschema.Draft4Validator(schema)
|
action='create',
|
||||||
self.assertFalse(validator.is_valid(body))
|
is_valid=False))
|
||||||
errors = sorted(validator.iter_errors(body), key=lambda e: e.path)
|
|
||||||
error_messages = [error.message for error in errors]
|
|
||||||
self.assertIn("-1 is less than the minimum of 0", error_messages)
|
self.assertIn("-1 is less than the minimum of 0", error_messages)
|
||||||
|
|
||||||
def test_validate_create_invalid_restart_required_3(self):
|
def test_validate_create_invalid_restart_required_3(self):
|
||||||
@ -249,10 +256,8 @@ class TestConfigurationsParameterController(trove_testtools.TestCase):
|
|||||||
'max': '255'
|
'max': '255'
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
schema = self.controller.get_schema('create', body)
|
error_messages = (
|
||||||
self.assertIsNotNone(schema)
|
self._test_validate_configuration_with_action(body,
|
||||||
validator = jsonschema.Draft4Validator(schema)
|
action='create',
|
||||||
self.assertFalse(validator.is_valid(body))
|
is_valid=False))
|
||||||
errors = sorted(validator.iter_errors(body), key=lambda e: e.path)
|
|
||||||
error_messages = [error.message for error in errors]
|
|
||||||
self.assertIn("'yes' is not of type 'integer'", error_messages)
|
self.assertIn("'yes' is not of type 'integer'", error_messages)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user