From 97aed6e9aacac058843c94561779f0ac90657843 Mon Sep 17 00:00:00 2001 From: Vitor Hideyoshi Date: Wed, 20 Aug 2025 00:30:54 -0300 Subject: [PATCH] (improvement): Adds tests for UUID String Format --- tests/parser/test_string_type_parser.py | 13 +++++++++++++ tests/test_schema_converter.py | 17 +++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/tests/parser/test_string_type_parser.py b/tests/parser/test_string_type_parser.py index e667ad7..279e20f 100644 --- a/tests/parser/test_string_type_parser.py +++ b/tests/parser/test_string_type_parser.py @@ -5,6 +5,7 @@ from pydantic import AnyUrl, EmailStr from datetime import date, datetime, time, timedelta from ipaddress import IPv4Address, IPv6Address from unittest import TestCase +from uuid import UUID class TestStringTypeParser(TestCase): @@ -131,6 +132,18 @@ class TestStringTypeParser(TestCase): self.assertEqual(type_parsing, expected_type) + def test_string_parser_with_uuid_format(self): + parser = StringTypeParser() + + properties = { + "type": "string", + "format": "uuid", + } + + type_parsing, type_validator = parser.from_properties("placeholder", properties) + + self.assertEqual(type_parsing, UUID) + def test_string_parser_with_time_format(self): parser = StringTypeParser() diff --git a/tests/test_schema_converter.py b/tests/test_schema_converter.py index d30a5ad..cdd294d 100644 --- a/tests/test_schema_converter.py +++ b/tests/test_schema_converter.py @@ -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",