diff options
Diffstat (limited to 'src')
| -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') |
