class TestConfigurationController(TestCase):
    def setUp(self):
        super(TestConfigurationController, self).setUp()
        self.controller = ConfigurationsController()

    def test_validate_create_configuration(self):
        body = {
            "configuration": {
                "values": {},
                "name": "test",
                "datastore": {"type": "test_type", "version": "test_version"},
            }
        }
        schema = self.controller.get_schema("create", body)
        self.assertIsNotNone(schema)
        validator = jsonschema.Draft4Validator(schema)
        self.assertTrue(validator.is_valid(body))

    def test_validate_create_configuration_no_datastore(self):
        body = {"configuration": {"values": {}, "name": "test"}}
        schema = self.controller.get_schema("create", body)
        self.assertIsNotNone(schema)
        validator = jsonschema.Draft4Validator(schema)
        self.assertTrue(validator.is_valid(body))

    def test_validate_create_invalid_values_param(self):
        body = {
            "configuration": {
                "values": "",
                "name": "test",
                "datastore": {"type": "test_type", "version": "test_version"},
            }
        }
        schema = self.controller.get_schema("create", body)
        self.assertIsNotNone(schema)
        validator = jsonschema.Draft4Validator(schema)
        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]
        self.assertIn("'' is not of type 'object'", error_messages)

    def test_validate_create_invalid_name_param(self):
        body = {
            "configuration": {"values": {}, "name": "", "datastore": {"type": "test_type", "version": "test_version"}}
        }
        schema = self.controller.get_schema("create", body)
        self.assertIsNotNone(schema)
        validator = jsonschema.Draft4Validator(schema)
        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]
        self.assertIn("'' is too short", error_messages)

    def test_validate_edit_configuration(self):
        body = {"configuration": {"values": {}}}
        schema = self.controller.get_schema("edit", body)
        self.assertIsNotNone(schema)
        validator = jsonschema.Draft4Validator(schema)
        self.assertTrue(validator.is_valid(body))
Exemple #2
0
class TestConfigurationController(TestCase):
    def setUp(self):
        super(TestConfigurationController, self).setUp()
        self.controller = ConfigurationsController()

    def test_validate_create_configuration(self):
        body = {
            "configuration": {
                "values": {},
                "name": "test",
                "datastore": {
                    "type": "test_type",
                    "version": "test_version"
                }
            }
        }
        schema = self.controller.get_schema('create', body)
        self.assertIsNotNone(schema)
        validator = jsonschema.Draft4Validator(schema)
        self.assertTrue(validator.is_valid(body))

    def test_validate_create_configuration_no_datastore(self):
        body = {"configuration": {"values": {}, "name": "test"}}
        schema = self.controller.get_schema('create', body)
        self.assertIsNotNone(schema)
        validator = jsonschema.Draft4Validator(schema)
        self.assertTrue(validator.is_valid(body))

    def test_validate_create_invalid_values_param(self):
        body = {
            "configuration": {
                "values": '',
                "name": "test",
                "datastore": {
                    "type": "test_type",
                    "version": "test_version"
                }
            }
        }
        schema = self.controller.get_schema('create', body)
        self.assertIsNotNone(schema)
        validator = jsonschema.Draft4Validator(schema)
        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]
        self.assertIn("'' is not of type 'object'", error_messages)

    def test_validate_create_invalid_name_param(self):
        body = {
            "configuration": {
                "values": {},
                "name": "",
                "datastore": {
                    "type": "test_type",
                    "version": "test_version"
                }
            }
        }
        schema = self.controller.get_schema('create', body)
        self.assertIsNotNone(schema)
        validator = jsonschema.Draft4Validator(schema)
        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]
        self.assertIn("'' is too short", error_messages)

    def test_validate_edit_configuration(self):
        body = {"configuration": {"values": {}}}
        schema = self.controller.get_schema('edit', body)
        self.assertIsNotNone(schema)
        validator = jsonschema.Draft4Validator(schema)
        self.assertTrue(validator.is_valid(body))

    def _test_validate_configuration(self, input_values, config_rules=None):
        if config_rules is None:
            config_val1 = MagicMock()
            config_val1.name = 'max_connections'
            config_val1.restart_required = 'false'
            config_val1.datastore_version_id = 5.5
            config_val1.max = 1
            config_val1.min = 0
            config_val1.data_type = 'integer'
            config_rules = [config_val1]

        data_version = MagicMock()
        data_version.id = 42
        data_version.name = 5.5
        data_version.datastore_name = 'test'

        self.assertRaises(UnprocessableEntity,
                          ConfigurationsController._validate_configuration,
                          input_values, data_version, config_rules)

    def test_validate_configuration_with_no_rules(self):
        self._test_validate_configuration({'max_connections': 5}, [])

    def test_validate_configuration_with_invalid_param(self):
        self._test_validate_configuration({'test': 5})

    def test_validate_configuration_with_invalid_type(self):
        self._test_validate_configuration({'max_connections': '1'})

    def test_validate_configuration_with_invalid_max(self):
        self._test_validate_configuration({'max_connections': 5})

    def test_validate_configuration_with_invalid_min(self):
        self._test_validate_configuration({'max_connections': -1})

    def test_validate_long_value(self):
        config_val1 = MagicMock()
        config_val1.name = 'myisam_sort_buffer_size'
        config_val1.max_size = 18446744073709551615
        config_val1.min_size = 4096
        config_val1.data_type = 'integer'
        config_rules = [config_val1]

        ConfigurationsController._validate_configuration(
            {'myisam_sort_buffer_size': 18446744073709551615}, None,
            config_rules)
class TestConfigurationController(TestCase):
    def setUp(self):
        super(TestConfigurationController, self).setUp()
        self.controller = ConfigurationsController()

    def test_validate_create_configuration(self):
        body = {
            "configuration": {
                "values": {},
                "name": "test",
                "datastore": {
                    "type": "test_type",
                    "version": "test_version"
                }
            }
        }
        schema = self.controller.get_schema('create', body)
        self.assertIsNotNone(schema)
        validator = jsonschema.Draft4Validator(schema)
        self.assertTrue(validator.is_valid(body))

    def test_validate_create_configuration_no_datastore(self):
        body = {
            "configuration": {
                "values": {},
                "name": "test"
            }
        }
        schema = self.controller.get_schema('create', body)
        self.assertIsNotNone(schema)
        validator = jsonschema.Draft4Validator(schema)
        self.assertTrue(validator.is_valid(body))

    def test_validate_create_invalid_values_param(self):
        body = {
            "configuration": {
                "values": '',
                "name": "test",
                "datastore": {
                    "type": "test_type",
                    "version": "test_version"
                }
            }
        }
        schema = self.controller.get_schema('create', body)
        self.assertIsNotNone(schema)
        validator = jsonschema.Draft4Validator(schema)
        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]
        self.assertIn("'' is not of type 'object'", error_messages)

    def test_validate_create_invalid_name_param(self):
        body = {
            "configuration": {
                "values": {},
                "name": "",
                "datastore": {
                    "type": "test_type",
                    "version": "test_version"
                }
            }
        }
        schema = self.controller.get_schema('create', body)
        self.assertIsNotNone(schema)
        validator = jsonschema.Draft4Validator(schema)
        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]
        self.assertIn("'' is too short", error_messages)

    def test_validate_edit_configuration(self):
        body = {
            "configuration": {
                "values": {}
            }
        }
        schema = self.controller.get_schema('edit', body)
        self.assertIsNotNone(schema)
        validator = jsonschema.Draft4Validator(schema)
        self.assertTrue(validator.is_valid(body))
class TestConfigurationController(TestCase):
    def setUp(self):
        super(TestConfigurationController, self).setUp()
        self.controller = ConfigurationsController()

    def test_validate_create_configuration(self):
        body = {
            "configuration": {
                "values": {},
                "name": "test",
                "datastore": {
                    "type": "test_type",
                    "version": "test_version"
                }
            }
        }
        schema = self.controller.get_schema('create', body)
        self.assertIsNotNone(schema)
        validator = jsonschema.Draft4Validator(schema)
        self.assertTrue(validator.is_valid(body))

    def test_validate_create_configuration_no_datastore(self):
        body = {
            "configuration": {
                "values": {},
                "name": "test"
            }
        }
        schema = self.controller.get_schema('create', body)
        self.assertIsNotNone(schema)
        validator = jsonschema.Draft4Validator(schema)
        self.assertTrue(validator.is_valid(body))

    def test_validate_create_invalid_values_param(self):
        body = {
            "configuration": {
                "values": '',
                "name": "test",
                "datastore": {
                    "type": "test_type",
                    "version": "test_version"
                }
            }
        }
        schema = self.controller.get_schema('create', body)
        self.assertIsNotNone(schema)
        validator = jsonschema.Draft4Validator(schema)
        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]
        self.assertIn("'' is not of type 'object'", error_messages)

    def test_validate_create_invalid_name_param(self):
        body = {
            "configuration": {
                "values": {},
                "name": "",
                "datastore": {
                    "type": "test_type",
                    "version": "test_version"
                }
            }
        }
        schema = self.controller.get_schema('create', body)
        self.assertIsNotNone(schema)
        validator = jsonschema.Draft4Validator(schema)
        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]
        self.assertIn("'' is too short", error_messages)

    def test_validate_edit_configuration(self):
        body = {
            "configuration": {
                "values": {}
            }
        }
        schema = self.controller.get_schema('edit', body)
        self.assertIsNotNone(schema)
        validator = jsonschema.Draft4Validator(schema)
        self.assertTrue(validator.is_valid(body))

    def _test_validate_configuration(self, input_values, config_rules=None):
        if config_rules is None:
            config_val1 = MagicMock()
            config_val1.name = 'max_connections'
            config_val1.restart_required = 'false'
            config_val1.datastore_version_id = 5.5
            config_val1.max = 1
            config_val1.min = 0
            config_val1.data_type = 'integer'
            config_rules = [config_val1]

        data_version = MagicMock()
        data_version.id = 42
        data_version.name = 5.5
        data_version.datastore_name = 'test'

        self.assertRaises(UnprocessableEntity,
                          ConfigurationsController._validate_configuration,
                          input_values,
                          data_version,
                          config_rules)

    def test_validate_configuration_with_no_rules(self):
        self._test_validate_configuration({'max_connections': 5}, [])

    def test_validate_configuration_with_invalid_param(self):
        self._test_validate_configuration({'test': 5})

    def test_validate_configuration_with_invalid_type(self):
        self._test_validate_configuration({'max_connections': '1'})

    def test_validate_configuration_with_invalid_max(self):
        self._test_validate_configuration({'max_connections': 5})

    def test_validate_configuration_with_invalid_min(self):
        self._test_validate_configuration({'max_connections': -1})

    def test_validate_long_value(self):
        config_val1 = MagicMock()
        config_val1.name = 'myisam_sort_buffer_size'
        config_val1.max_size = 18446744073709551615
        config_val1.min_size = 4096
        config_val1.data_type = 'integer'
        config_rules = [config_val1]

        ConfigurationsController._validate_configuration(
            {'myisam_sort_buffer_size': 18446744073709551615},
            None, config_rules)