Barry Warsaw pushed to branch master at mailman / Mailman
Commits: 5f9634cc by Aurélien Bompard at 2016-01-13T11:36:30-05:00 Fix getting a list member through the 3.1 API - - - - - 06159312 by Barry Warsaw at 2016-01-13T12:00:19-05:00 Use common idiom for converting the UUID. Wrap lines. - - - - - 2 changed files: - src/mailman/rest/members.py - src/mailman/rest/tests/test_membership.py Changes: ===================================== src/mailman/rest/members.py ===================================== --- a/src/mailman/rest/members.py +++ b/src/mailman/rest/members.py @@ -107,19 +107,22 @@ 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_id): + # The member_id is either the member's UUID or the string + # representation of the member's UUID. 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 - else: - service = getUtility(ISubscriptionService) + self._member = None + service = getUtility(ISubscriptionService) + if isinstance(member_id, UUID): self._member = service.get_member(member_id) + else: + try: + member_id = api.to_uuid(member_id) + except ValueError: + # The string argument could not be converted to a UUID. + pass + else: + self._member = service.get_member(member_id) def on_get(self, request, response): """Return a single member end-point.""" ===================================== src/mailman/rest/tests/test_membership.py ===================================== --- 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/aper...@example.com') + def test_get_list_member_id_by_email(self): + with transaction(): + subscribe(self._mlist, 'Anne', email="aper...@example.com") + response, headers = call_api( + 'http://localhost:9001/3.1/lists/ant.example.com/member' + '/aper...@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/aper...@example.com') + def test_cannot_get_member_id_by_int(self): with transaction(): subscribe(self._mlist, 'Anne') View it on GitLab: https://gitlab.com/mailman/mailman/compare/98c074f19492d81ebf5b5c3f4d4f2210aa56230d...06159312d09192b1cede8d20b61ff856442426e8
_______________________________________________ Mailman-checkins mailing list Mailman-checkins@python.org Unsubscribe: https://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org