diff options
| author | Aurélien Bompard | 2016-01-12 19:54:36 +0100 |
|---|---|---|
| committer | Barry Warsaw | 2016-01-13 11:36:30 -0500 |
| commit | 5f9634cc11baee8256e037564b362b0631e269fe (patch) | |
| tree | 0bb5e5252c1d09e0f5a6f428e966d8980b6b426e | |
| parent | 98c074f19492d81ebf5b5c3f4d4f2210aa56230d (diff) | |
| download | mailman-5f9634cc11baee8256e037564b362b0631e269fe.tar.gz mailman-5f9634cc11baee8256e037564b362b0631e269fe.tar.zst mailman-5f9634cc11baee8256e037564b362b0631e269fe.zip | |
Fix getting a list member through the 3.1 API
| -rw-r--r-- | src/mailman/rest/members.py | 24 | ||||
| -rw-r--r-- | src/mailman/rest/tests/test_membership.py | 18 |
2 files changed, 31 insertions, 11 deletions
diff --git a/src/mailman/rest/members.py b/src/mailman/rest/members.py index 91db982c7..64e5ba23f 100644 --- a/src/mailman/rest/members.py +++ b/src/mailman/rest/members.py @@ -107,19 +107,21 @@ class MemberCollection(_MemberBase): class AMember(_MemberBase): """A member.""" - def __init__(self, api, member_id_string): - # The member_id_string is the string representation of the member's - # UUID. In API 3.0, the argument is the string representation of the - # int representation of the UUID. In API 3.1 it's the hex. + def __init__(self, api, member_or_id_string): + # The member_or_id_string is either the member's UUID or the string + # representation of the member's UUID. For the latter, in API 3.0, + # the argument is the string representation of the int representation + # of the UUID. In API 3.1 it's the hex. self.api = api - try: - member_id = api.to_uuid(member_id_string) - except ValueError: - # The string argument could not be converted to a UUID. - self._member = None + if isinstance(member_or_id_string, UUID): + member_id = member_or_id_string else: - service = getUtility(ISubscriptionService) - self._member = service.get_member(member_id) + try: + member_id = api.to_uuid(member_or_id_string) + except ValueError: + # The string argument could not be converted to a UUID. + self._member = None + self._member = getUtility(ISubscriptionService).get_member(member_id) def on_get(self, request, response): """Return a single member end-point.""" diff --git a/src/mailman/rest/tests/test_membership.py b/src/mailman/rest/tests/test_membership.py index a7f54703a..d69fedb35 100644 --- a/src/mailman/rest/tests/test_membership.py +++ b/src/mailman/rest/tests/test_membership.py @@ -518,6 +518,24 @@ class TestAPI31Members(unittest.TestCase): response['address'], 'http://localhost:9001/3.1/addresses/aperson@example.com') + def test_get_list_member_id_by_email(self): + with transaction(): + subscribe(self._mlist, 'Anne', email="aperson@example.com") + response, headers = call_api( + 'http://localhost:9001/3.1/lists/ant.example.com/member/aperson@example.com') + self.assertEqual( + response['member_id'], + '00000000000000000000000000000001') + self.assertEqual( + response['self_link'], + 'http://localhost:9001/3.1/members/00000000000000000000000000000001') + self.assertEqual( + response['user'], + 'http://localhost:9001/3.1/users/00000000000000000000000000000001') + self.assertEqual( + response['address'], + 'http://localhost:9001/3.1/addresses/aperson@example.com') + def test_cannot_get_member_id_by_int(self): with transaction(): subscribe(self._mlist, 'Anne') |
