From e979464e4cd836cdbfffbb2b803edb71b21a3a86 Mon Sep 17 00:00:00 2001 From: J08nY Date: Tue, 15 Aug 2017 22:47:29 +0200 Subject: Make enumflag work with mailmanclients serializing of lists. --- src/mailman_pgp/rest/tests/test_lists.py | 11 +++++++++++ src/mailman_pgp/utils/rest.py | 13 +++++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/mailman_pgp/rest/tests/test_lists.py b/src/mailman_pgp/rest/tests/test_lists.py index 8e3ba31..5d7c6aa 100644 --- a/src/mailman_pgp/rest/tests/test_lists.py +++ b/src/mailman_pgp/rest/tests/test_lists.py @@ -21,6 +21,7 @@ from urllib.error import HTTPError from mailman.app.lifecycle import create_list from mailman.interfaces.action import Action +from mailman.interfaces.member import MemberRole from mailman.testing.helpers import call_api from pgpy import PGPKey @@ -170,6 +171,16 @@ class TestListConfig(TestCase): self.assertEqual(response.status_code, 204) self.assertEqual(self.pgp_list.unsigned_msg_action, Action.defer) + def test_patch_set(self): + json, response = call_api( + 'http://localhost:9001/3.1/plugins/pgp/lists/' + 'test.example.com', + data=dict(key_signing_allowed=['member', 'owner']), + method='PATCH') + self.assertEqual(response.status_code, 204) + self.assertEqual(self.pgp_list.key_signing_allowed, + {MemberRole.member, MemberRole.owner}) + def test_patch_wrong_attribute(self): with self.assertRaises(HTTPError) as cm: call_api('http://localhost:9001/3.1/plugins/pgp/lists/' diff --git a/src/mailman_pgp/utils/rest.py b/src/mailman_pgp/utils/rest.py index 4e31b0c..a44575c 100644 --- a/src/mailman_pgp/utils/rest.py +++ b/src/mailman_pgp/utils/rest.py @@ -14,6 +14,7 @@ # # You should have received a copy of the GNU General Public License along with # this program. If not, see . +import ast class enumflag_validator: @@ -26,8 +27,16 @@ class enumflag_validator: for val in value: result.add(self.enum[val]) return result - - return {self.enum[value]} + if value in self.enum: + return {self.enum[value]} + else: + l = ast.literal_eval(value) + if isinstance(l, (list, tuple)): + result = set() + for val in l: + result.add(self.enum[val]) + return result + raise ValueError class workflow_validator: -- cgit v1.2.3-70-g09d2