Fixes Default Values in StringTypeParser
This commit is contained in:
@@ -73,7 +73,7 @@ class TestArrayTypeParser(TestCase):
|
||||
def test_array_parser_with_invalid_default_type(self):
|
||||
parser = ArrayTypeParser()
|
||||
|
||||
properties = {"items": {"type": "string"}, "default": "not_a_list"}
|
||||
properties = {"items": {"type": "string"}, "default": 000}
|
||||
|
||||
with self.assertRaises(ValueError):
|
||||
parser.from_properties("placeholder", properties)
|
||||
|
||||
@@ -9,7 +9,9 @@ class TestBoolTypeParser(TestCase):
|
||||
|
||||
properties = {"type": "boolean"}
|
||||
|
||||
type_parsing, type_validator = parser.from_properties("placeholder", properties)
|
||||
type_parsing, type_validator = parser.from_properties_impl(
|
||||
"placeholder", properties
|
||||
)
|
||||
|
||||
self.assertEqual(type_parsing, bool)
|
||||
self.assertEqual(type_validator, {"default": None})
|
||||
@@ -22,7 +24,9 @@ class TestBoolTypeParser(TestCase):
|
||||
"default": True,
|
||||
}
|
||||
|
||||
type_parsing, type_validator = parser.from_properties("placeholder", properties)
|
||||
type_parsing, type_validator = parser.from_properties_impl(
|
||||
"placeholder", properties
|
||||
)
|
||||
|
||||
self.assertEqual(type_parsing, bool)
|
||||
self.assertEqual(type_validator["default"], True)
|
||||
@@ -36,4 +40,4 @@ class TestBoolTypeParser(TestCase):
|
||||
}
|
||||
|
||||
with self.assertRaises(ValueError):
|
||||
parser.from_properties("placeholder", properties)
|
||||
parser.from_properties_impl("placeholder", properties)
|
||||
|
||||
@@ -15,7 +15,7 @@ class TestObjectTypeParser(TestCase):
|
||||
},
|
||||
}
|
||||
|
||||
Model, _args = parser.from_properties("placeholder", properties)
|
||||
Model, _args = parser.from_properties_impl("placeholder", properties)
|
||||
|
||||
obj = Model(name="name", age=10)
|
||||
|
||||
@@ -37,7 +37,7 @@ class TestObjectTypeParser(TestCase):
|
||||
},
|
||||
}
|
||||
|
||||
_, type_validator = parser.from_properties("placeholder", properties)
|
||||
_, type_validator = parser.from_properties_impl("placeholder", properties)
|
||||
|
||||
# Check default value
|
||||
default_obj = type_validator["default_factory"]()
|
||||
|
||||
@@ -11,7 +11,7 @@ def with_test_parser():
|
||||
mapped_type = str
|
||||
json_schema_type = "type:invalid"
|
||||
|
||||
def from_properties(
|
||||
def from_properties_impl(
|
||||
self, name: str, properties: dict[str, any], required: bool = False
|
||||
): ...
|
||||
|
||||
@@ -39,11 +39,3 @@ class TestGenericTypeParser(TestCase):
|
||||
):
|
||||
InvalidGenericTypeParser.json_schema_type = None
|
||||
GenericTypeParser._get_impl({"type": "another_invalid_type"})
|
||||
|
||||
def test_invalid_mappings_properties_builder(self):
|
||||
with (
|
||||
with_test_parser() as InvalidGenericTypeParser,
|
||||
self.assertRaises(NotImplementedError),
|
||||
):
|
||||
parser = InvalidGenericTypeParser()
|
||||
parser.mappings_properties_builder({}, required=False)
|
||||
|
||||
@@ -255,6 +255,7 @@ class TestSchemaConverter(TestCase):
|
||||
|
||||
self.assertEqual(obj.name, "John")
|
||||
|
||||
def test_invalid_default_for_string(self):
|
||||
# Test for default with maxLength
|
||||
schema_max_length = {
|
||||
"title": "Person",
|
||||
|
||||
Reference in New Issue
Block a user