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 import helpers
from 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, '')
self.assertEqual('', email_validator(''))
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)
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():
values[key] = self._converters[key](value)
if (self._converters[key] is as_boolean and
isinstance(value, bool)):
values[key] = value
values[key] = self._converters[key](value)
except KeyError:
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