Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert Email, Url, and FqdnUrl to corresponding lowercase format #8

Merged
merged 1 commit into from
Aug 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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