Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃悰 Fix handling of UUID values having UUID.version=None #7566

Merged
merged 1 commit into from Sep 22, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
41 changes: 38 additions & 3 deletions tests/test_types.py
Expand Up @@ -2758,17 +2758,19 @@ class UUIDModel(BaseModel):
b: UUID3
c: UUID4
d: UUID5
e: UUID

a = uuid.uuid1()
b = uuid.uuid3(uuid.NAMESPACE_DNS, 'python.org')
c = uuid.uuid4()
d = uuid.uuid5(uuid.NAMESPACE_DNS, 'python.org')
e = UUID('{00000000-7fff-4000-7fff-000000000000}')

m = UUIDModel(a=a, b=b, c=c, d=d)
assert m.model_dump() == {'a': a, 'b': b, 'c': c, 'd': d}
m = UUIDModel(a=a, b=b, c=c, d=d, e=e)
assert m.model_dump() == {'a': a, 'b': b, 'c': c, 'd': d, 'e': e}

with pytest.raises(ValidationError) as exc_info:
UUIDModel(a=d, b=c, c=b, d=a)
UUIDModel(a=d, b=c, c=b, d=a, e=e)
# insert_assert(exc_info.value.errors(include_url=False))
assert exc_info.value.errors(include_url=False) == [
{
Expand Down Expand Up @@ -2801,6 +2803,39 @@ class UUIDModel(BaseModel):
},
]

with pytest.raises(ValidationError) as exc_info:
UUIDModel(a=e, b=e, c=e, d=e, e=e)
assert exc_info.value.errors(include_url=False) == [
{
'type': 'uuid_version',
'loc': ('a',),
'msg': 'UUID version 1 expected',
'input': e,
'ctx': {'expected_version': 1},
},
{
'type': 'uuid_version',
'loc': ('b',),
'msg': 'UUID version 3 expected',
'input': e,
'ctx': {'expected_version': 3},
},
{
'type': 'uuid_version',
'loc': ('c',),
'msg': 'UUID version 4 expected',
'input': e,
'ctx': {'expected_version': 4},
},
{
'type': 'uuid_version',
'loc': ('d',),
'msg': 'UUID version 5 expected',
'input': e,
'ctx': {'expected_version': 5},
},
]


def test_uuid_strict() -> None:
class UUIDModel(BaseModel):
Expand Down