From 113bf066477ada54f182724fc81a574d3d143657 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ville=20Skytt=C3=A4?= Date: Thu, 8 Aug 2019 01:32:06 +0300 Subject: [PATCH] Convert Email, Url, and FqdnUrl to corresponding lowercase format (#8) --- tests/test_lib.py | 21 +++++++++++++++++++++ voluptuous_serialize/__init__.py | 5 +++++ 2 files changed, 26 insertions(+) diff --git a/tests/test_lib.py b/tests/test_lib.py index 9e0e2d0..30a5a37 100644 --- a/tests/test_lib.py +++ b/tests/test_lib.py @@ -142,3 +142,24 @@ def test_strip(): 'type': 'string', 'strip': True, } == convert(vol.Schema(vol.All(vol.Strip, str))) + + +def test_email(): + assert { + 'type': 'string', + 'format': 'email', + } == convert(vol.Schema(vol.All(vol.Email, str))) + + +def test_url(): + assert { + 'type': 'string', + 'format': 'url', + } == convert(vol.Schema(vol.All(vol.Url, str))) + + +def test_fqdnurl(): + assert { + 'type': 'string', + 'format': 'fqdnurl', + } == convert(vol.Schema(vol.All(vol.FqdnUrl, str))) diff --git a/voluptuous_serialize/__init__.py b/voluptuous_serialize/__init__.py index 8bc2676..110eafe 100644 --- a/voluptuous_serialize/__init__.py +++ b/voluptuous_serialize/__init__.py @@ -88,6 +88,11 @@ def convert(schema): schema.__name__.lower(): True, } + if schema in (vol.Email, vol.Url, vol.FqdnUrl): + return { + 'format': schema.__name__.lower(), + } + if isinstance(schema, vol.Coerce): schema = schema.type