Mark Sapiro pushed to branch master at GNU Mailman / Mailman Core
Commits:
8893052d by Mark Sapiro at 2022-01-18T21:25:56-08:00
Accept JSON encoded booleans in the REST API.
- - - - -
c3860006 by Mark Sapiro at 2022-01-19T16:01:21+00:00
Merge branch 'bool' into 'master'
Accept JSON encoded booleans in the REST API.
Closes #970
See merge request mailman/mailman!949
- - - - -
4 changed files:
- src/mailman/docs/NEWS.rst
- src/mailman/rest/helpers.py
- src/mailman/rest/tests/test_listconf.py
- src/mailman/rest/tests/test_validator.py
Changes:
=====================================
src/mailman/docs/NEWS.rst
=====================================
@@ -29,6 +29,8 @@ Bugs fixed
* Decoration of an html message containing non-ascii resulted in a message
that couldn't by flattened as_bytes and whose as_string representation
contained non-ascii. This is fixed. (Closes #965 and #967)
+* The REST API will now accept JSON encoded data with boolean values for
+ boolean attributes. (Closes #970)
.. _news-3.3.5:
=====================================
src/mailman/rest/helpers.py
=====================================
@@ -249,6 +249,8 @@ class GetterSetter:
"""
if self.decoder is None:
return value
+ if self.decoder is as_boolean and isinstance(value, bool):
+ return value
return self.decoder(value)
=====================================
src/mailman/rest/tests/test_listconf.py
=====================================
@@ -292,6 +292,17 @@ class TestConfiguration(unittest.TestCase):
'Invalid Parameter "archive_policy": Accepted Values are:'
' never, private, public.')
+ def test_patch_with_json_boolean(self):
+ # Ensure we can patch with JSON boolean value.
+ with transaction():
+ self._mlist.gateway_to_mail = False
+ response = call_api(
+ 'http://localhost:9001/3.0/lists/ant.example.com/config',
+ method='PATCH', headers={'Content-Type': 'application/json'},
+ json={'gateway_to_mail': True})
+ self.assertEqual(response[1].status_code, 204)
+ self.assertTrue(self._mlist.gateway_to_mail)
+
def test_bad_pipeline_name(self):
with self.assertRaises(HTTPError) as cm:
call_api(
=====================================
src/mailman/rest/tests/test_validator.py
=====================================
@@ -19,6 +19,7 @@
import unittest
+from lazr.config import as_boolean
from mailman.app.lifecycle import create_list
from mailman.core.api import API30, API31
from mailman.database.transaction import transaction
@@ -170,3 +171,10 @@ class TestGetterSetter(unittest.TestCase):
['application/octet-stream'])
self.assertEqual(list(self._mlist.pass_extensions),
['.pdf'])
+
+ def test_set_boolean_as_bool(self):
+ # Non-pythonic POST data can contain JSON booleans. Ensure we can
+ # handle that.
+ getset = helpers.GetterSetter(as_boolean)
+ self.assertTrue(getset(True))
+ self.assertFalse(getset(False))
View it on GitLab:
https://gitlab.com/mailman/mailman/-/compare/f9afc476255c638e1fdbe564323bcfbd916197fd...c38600069354e9b7a66cd2df0023f723cdc9c462
--
View it on GitLab:
https://gitlab.com/mailman/mailman/-/compare/f9afc476255c638e1fdbe564323bcfbd916197fd...c38600069354e9b7a66cd2df0023f723cdc9c462
You're receiving this email because of your account on gitlab.com.
_______________________________________________
Mailman-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/mailman-checkins.python.org/
Member address: [email protected]