(improvement): Adds tests for UUID String Format
This commit is contained in:
@@ -4,6 +4,7 @@ from pydantic import AnyUrl, BaseModel
|
||||
|
||||
from ipaddress import IPv4Address, IPv6Address
|
||||
from unittest import TestCase
|
||||
from uuid import UUID
|
||||
|
||||
|
||||
def is_pydantic_model(cls):
|
||||
@@ -493,6 +494,22 @@ class TestSchemaConverter(TestCase):
|
||||
with self.assertRaises(ValueError):
|
||||
model(ip="invalid-ipv6")
|
||||
|
||||
def test_string_format_uuid(self):
|
||||
schema = {
|
||||
"title": "UUIDTest",
|
||||
"type": "object",
|
||||
"properties": {"id": {"type": "string", "format": "uuid"}},
|
||||
}
|
||||
model = SchemaConverter.build(schema)
|
||||
|
||||
self.assertEqual(
|
||||
model(id="123e4567-e89b-12d3-a456-426614174000").id,
|
||||
UUID("123e4567-e89b-12d3-a456-426614174000"),
|
||||
)
|
||||
|
||||
with self.assertRaises(ValueError):
|
||||
model(id="invalid-uuid")
|
||||
|
||||
def test_string_format_hostname(self):
|
||||
schema = {
|
||||
"title": "HostnameTest",
|
||||
|
||||
Reference in New Issue
Block a user