class TestValidateFloat(unittest.TestCase): def setUp(self): self.model = Model({ 'shapes': { 'TestShape': { 'type': 'float', 'min': 0, 'max': 1, } } }) def test_validate_integer_0(self): report = validate_shape(self.model.get_shape('TestShape'), 0) self.assertEqual(len(report), 0) def test_validate_integer_1(self): report = validate_shape(self.model.get_shape('TestShape'), 1) self.assertEqual(len(report), 0) def test_validate_integer_min(self): report = validate_shape(self.model.get_shape('TestShape'), -1) self.assertEqual(len(report), 1) self.assertEqual(report[0].code, "invalid_range") def test_validate_integer_max(self): report = validate_shape(self.model.get_shape('TestShape'), -1) self.assertEqual(len(report), 1) self.assertEqual(report[0].code, "invalid_range") def test_validate_integer_type_check(self): report = validate_shape(self.model.get_shape('TestShape'), "55") self.assertEqual(len(report), 1) self.assertEqual(report[0].code, "invalid_type")
class TestValidateList(unittest.TestCase): def setUp(self): self.model = Model({ 'shapes': { 'String': { 'type': 'string', }, 'TestStructure': { 'type': 'structure', 'members': [{ 'name': 'foo', 'shape': 'String', }] }, 'TestShape': { 'type': 'list', 'of': 'TestStructure', 'min': 1, 'max': 1, } } }) def test_validate_list_type_check(self): report = validate_shape(self.model.get_shape('TestShape'), 55) self.assertEqual(len(report), 1) self.assertEqual(report[0].code, "invalid_type") def test_validate_list_min(self): report = validate_shape(self.model.get_shape('TestShape'), []) self.assertEqual(len(report), 1) self.assertEqual(report[0].code, "invalid_range") def test_validate_list_max(self): report = validate_shape(self.model.get_shape('TestShape'), [ {"foo": ""}, {"foo": ""}, ]) self.assertEqual(len(report), 1) self.assertEqual(report[0].code, "invalid_range") def test_validate_child_type_check(self): report = validate_shape(self.model.get_shape('TestShape'), [1]) self.assertEqual(len(report), 1) self.assertEqual(report[0].code, "invalid_type") self.assertEqual(report[0].field, "[0]") def test_validate_child_child_type_check(self): report = validate_shape( self.model.get_shape('TestShape'), [{"foo": 1}] ) self.assertEqual(len(report), 1) self.assertEqual(report[0].code, "invalid_type") self.assertEqual(report[0].field, "[0].foo")
class TestValidateStructure(unittest.TestCase): def setUp(self): self.model = Model({ 'shapes': { 'String': { 'type': 'string', }, 'TestShape': { 'type': 'structure', 'members': [{ 'name': 'foo', 'shape': 'String', 'required': True, }] } } }) def test_validate_structure_type_check(self): report = validate_shape(self.model.get_shape('TestShape'), 55) self.assertEqual(len(report), 1) self.assertEqual(report[0].code, "invalid_type") def test_validate_structure_unknown_param(self): report = validate_shape( self.model.get_shape('TestShape'), {"foo": "a", "bar": "a"} ) self.assertEqual(len(report), 1) self.assertEqual(report[0].code, "unexpected_field") self.assertEqual(report[0].field, "bar") def test_validate_structure_child_type_check(self): report = validate_shape(self.model.get_shape('TestShape'), {"foo": 1}) self.assertEqual(len(report), 1) self.assertEqual(report[0].code, "invalid_type") self.assertEqual(report[0].field, "foo") def test_validate_structure_missing_required(self): report = validate_shape(self.model.get_shape('TestShape'), {}) self.assertEqual(len(report), 1) self.assertEqual(report[0].code, "required_field_missing") self.assertEqual(report[0].field, "foo")
def test_validate_string_no(self): model = Model({ 'shapes': { 'TestShape': { 'type': 'string', } } }) report = validate_shape(model.get_shape('TestShape'), "test") self.assertEqual(len(report), 0)
def test_validate_string_type_check(self): model = Model({ 'shapes': { 'TestShape': { 'type': 'string', } } }) report = validate_shape(model.get_shape('TestShape'), 55) self.assertEqual(len(report), 1) self.assertEqual(report[0].code, "invalid_type")
def test_validate_string_regex_check(self): model = Model({ 'shapes': { 'TestShape': { 'type': 'string', 'regex': '^$', } } }) report = validate_shape(model.get_shape('TestShape'), "foo") self.assertEqual(len(report), 1) self.assertEqual(report[0].code, "value_fails_regex")
def test_validate_string_max_fail(self): model = Model({ 'shapes': { 'TestShape': { 'type': 'string', 'max': 1, } } }) report = validate_shape(model.get_shape('TestShape'), "test") self.assertEqual(len(report), 1) self.assertEqual(report[0].code, "invalid_range")
class TestValidateBool(unittest.TestCase): def setUp(self): self.model = Model({ 'shapes': { 'TestShape': { 'type': 'boolean', } } }) def test_validate_bool_true(self): report = validate_shape(self.model.get_shape('TestShape'), True) self.assertEqual(len(report), 0) def test_validate_bool_false(self): report = validate_shape(self.model.get_shape('TestShape'), False) self.assertEqual(len(report), 0) def test_validate_bool_type_check(self): report = validate_shape(self.model.get_shape('TestShape'), 55) self.assertEqual(len(report), 1) self.assertEqual(report[0].code, "invalid_type")
class TestValidateMap(unittest.TestCase): def setUp(self): self.model = Model({ 'shapes': { 'String': { 'type': 'string', }, 'TestShape': { 'type': 'map', 'key': 'String', 'value': 'String', 'min': 1, 'max': 1, } } }) def test_validate_map_success(self): report = validate_shape(self.model.get_shape('TestShape'), {1: "foo"}) self.assertEqual(len(report), 1) self.assertEqual(report[0].code, "invalid_type") def test_validate_map_type_check(self): report = validate_shape(self.model.get_shape('TestShape'), 55) self.assertEqual(len(report), 1) self.assertEqual(report[0].code, "invalid_type") def test_validate_map_key(self): report = validate_shape(self.model.get_shape('TestShape'), {1: "foo"}) self.assertEqual(len(report), 1) self.assertEqual(report[0].code, "invalid_type") def test_validate_map_value(self): report = validate_shape(self.model.get_shape('TestShape'), {"foo": 1}) self.assertEqual(len(report), 1) self.assertEqual(report[0].code, "invalid_type") def test_validate_min(self): report = validate_shape(self.model.get_shape('TestShape'), {}) self.assertEqual(len(report), 1) self.assertEqual(report[0].code, "invalid_range") def test_validate_max(self): report = validate_shape(self.model.get_shape('TestShape'), { "a": "b", "c": "d", }) self.assertEqual(len(report), 1) self.assertEqual(report[0].code, "invalid_range")