mirror of
https://github.com/kennethreitz/pydantic.git
synced 2026-06-05 23:00:18 +00:00
Replacing encode_default instance check with strict type check (#3197)
* Replacing encode_default instance check with strict type check * Adding change notes * Changing to dictionary indexing in tests * Adding explicit Enum check and returning its value
This commit is contained in:
@@ -1435,6 +1435,26 @@ def test_list_default():
|
||||
}
|
||||
|
||||
|
||||
def test_enum_str_default():
|
||||
class MyEnum(str, Enum):
|
||||
FOO = 'foo'
|
||||
|
||||
class UserModel(BaseModel):
|
||||
friends: MyEnum = MyEnum.FOO
|
||||
|
||||
assert UserModel.schema()['properties']['friends']['default'] is MyEnum.FOO.value
|
||||
|
||||
|
||||
def test_enum_int_default():
|
||||
class MyEnum(IntEnum):
|
||||
FOO = 1
|
||||
|
||||
class UserModel(BaseModel):
|
||||
friends: MyEnum = MyEnum.FOO
|
||||
|
||||
assert UserModel.schema()['properties']['friends']['default'] is MyEnum.FOO.value
|
||||
|
||||
|
||||
def test_dict_default():
|
||||
class UserModel(BaseModel):
|
||||
friends: Dict[str, float] = {'a': 1.1, 'b': 2.2}
|
||||
|
||||
Reference in New Issue
Block a user