(improvement): Adds More Type Formats to String Parser
This commit is contained in:
@@ -1,8 +1,9 @@
|
||||
from jambo.parser import StringTypeParser
|
||||
|
||||
from pydantic import EmailStr, HttpUrl, IPvAnyAddress
|
||||
from pydantic import AnyUrl, EmailStr
|
||||
|
||||
from datetime import date, datetime, time, timedelta
|
||||
from ipaddress import IPv4Address, IPv6Address
|
||||
from unittest import TestCase
|
||||
|
||||
|
||||
@@ -111,12 +112,14 @@ class TestStringTypeParser(TestCase):
|
||||
|
||||
type_parsing, type_validator = parser.from_properties("placeholder", properties)
|
||||
|
||||
self.assertEqual(type_parsing, HttpUrl)
|
||||
self.assertEqual(type_parsing, AnyUrl)
|
||||
|
||||
def test_string_parser_with_ip_formats(self):
|
||||
parser = StringTypeParser()
|
||||
|
||||
for ip_format in ["ipv4", "ipv6"]:
|
||||
formats = {"ipv4": IPv4Address, "ipv6": IPv6Address}
|
||||
|
||||
for ip_format, expected_type in formats.items():
|
||||
properties = {
|
||||
"type": "string",
|
||||
"format": ip_format,
|
||||
@@ -126,7 +129,7 @@ class TestStringTypeParser(TestCase):
|
||||
"placeholder", properties
|
||||
)
|
||||
|
||||
self.assertEqual(type_parsing, IPvAnyAddress)
|
||||
self.assertEqual(type_parsing, expected_type)
|
||||
|
||||
def test_string_parser_with_time_format(self):
|
||||
parser = StringTypeParser()
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
from jambo import SchemaConverter
|
||||
|
||||
from pydantic import BaseModel, HttpUrl
|
||||
from pydantic import AnyUrl, BaseModel
|
||||
|
||||
from ipaddress import IPv4Address, IPv6Address
|
||||
from unittest import TestCase
|
||||
@@ -463,7 +463,7 @@ class TestSchemaConverter(TestCase):
|
||||
}
|
||||
model = SchemaConverter.build(schema)
|
||||
self.assertEqual(
|
||||
model(website="https://example.com").website, HttpUrl("https://example.com")
|
||||
model(website="https://example.com").website, AnyUrl("https://example.com")
|
||||
)
|
||||
with self.assertRaises(ValueError):
|
||||
model(website="invalid-uri")
|
||||
|
||||
Reference in New Issue
Block a user