Commit 9d72e46a authored by Mark Sapiro's avatar Mark Sapiro
Browse files

Merge branch 'bool' into 'master'

Extend fix for JSON encoded booleans to REST validator.

See merge request !950
parents 37b76913 7c0c47a6
Pipeline #454203007 passed with stage
in 11 minutes and 39 seconds
......@@ -27,7 +27,7 @@ from mailman.interfaces.action import Action
from mailman.interfaces.usermanager import IUserManager
from mailman.rest import helpers
from mailman.rest.validator import (
email_or_regexp_validator, email_validator, enum_validator,
Validator, email_or_regexp_validator, email_validator, enum_validator,
integer_ge_zero_validator, list_of_emails_validator,
list_of_strings_validator, subscriber_validator)
from mailman.testing.layers import RESTLayer
......@@ -147,6 +147,20 @@ class TestValidators(unittest.TestCase):
email_validator, 'foo.example.com')
self.assertEqual('foo@example.com', email_validator('foo@example.com'))
def test_validator_class_boolean_as_bool(self):
class RequestTrue:
params = dict(key=True)
content_type = 'application/x-www-form-urlencoded'
class RequestFalse:
params = dict(key=False)
content_type = 'application/x-www-form-urlencoded'
validator = Validator(key=as_boolean)
self.assertTrue(validator(RequestTrue)['key'])
self.assertFalse(validator(RequestFalse)['key'])
class TestGetterSetter(unittest.TestCase):
"""Test the GeterSetter class"""
......
......@@ -19,6 +19,7 @@
import re
from lazr.config import as_boolean
from mailman.interfaces.address import IEmailValidator
from mailman.interfaces.errors import MailmanError
from mailman.interfaces.languages import ILanguageManager
......@@ -224,7 +225,11 @@ class Validator:
# Now do all the conversions.
for key, value in form_data.items():
try:
values[key] = self._converters[key](value)
if (self._converters[key] is as_boolean and
isinstance(value, bool)):
values[key] = value
else:
values[key] = self._converters[key](value)
except KeyError:
extras.add(key)
except (TypeError, ValueError) as e:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment