Skip to content

Commit

Permalink
Convert Email, Url, and FqdnUrl to corresponding lowercase format (#8)
Browse files Browse the repository at this point in the history
  • Loading branch information
scop authored and balloob committed Aug 7, 2019
1 parent 02992eb commit 113bf06
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
21 changes: 21 additions & 0 deletions tests/test_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
5 changes: 5 additions & 0 deletions voluptuous_serialize/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down

0 comments on commit 113bf06

Please sign in to comment.