[prev in list] [next in list] [prev in thread] [next in thread] 

List:       mailman-cvs
Subject:    [Mailman-checkins] [Git][mailman/mailman][master] 2 commits: Fix getting a list member through the 3
From:       Barry Warsaw <gitlab () mg ! gitlab ! com>
Date:       2016-01-13 17:02:44
Message-ID: 5696833453b9b_61cb3ff0125f9668859fd () worker1 ! cluster ! gitlab ! com ! mail
[Download RAW message or body]

[Attachment #2 (multipart/alternative)]


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/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')



View it on GitLab: https://gitlab.com/mailman/mailman/compare/98c074f19492d81ebf5b5c3f4d4f2210aa56230d...06159312d09192b1cede8d20b61ff856442426e8



[Attachment #5 (text/html)]

<html lang='en'>
<head>
<meta content='text/html; charset=utf-8' http-equiv='Content-Type'>
<title>
GitLab
</title>
</meta>
</head>
<style>
  img {
    max-width: 100%;
    height: auto;
  }
  p.details {
    font-style:italic;
    color:#777
  }
  .footer p {
    font-size:small;
    color:#777
  }
  pre.commit-message {
    white-space: pre-wrap;
  }
  .file-stats a {
    text-decoration: none;
  }
  .file-stats .new-file {
    color: #090;
  }
  .file-stats .deleted-file {
    color: #B00;
  }
</style>
<body>
<div class='content'>
<h3>
Barry Warsaw pushed to branch master
at <a href="https://gitlab.com/mailman/mailman">mailman / Mailman</a>
</h3>
<h4>
Commits:
</h4>
<ul>
<li>
<strong><a href="https://gitlab.com/mailman/mailman/commit/5f9634cc11baee8256e037564b362b0631e269fe">5f9634cc</a></strong>
 <div>
<span>by Aurélien Bompard</span>
<i>at 2016-01-13T11:36:30-05:00</i>
</div>
<pre class='commit-message'>Fix getting a list member through the 3.1 API</pre>
</li>
<li>
<strong><a href="https://gitlab.com/mailman/mailman/commit/06159312d09192b1cede8d20b61ff856442426e8">06159312</a></strong>
 <div>
<span>by Barry Warsaw</span>
<i>at 2016-01-13T12:00:19-05:00</i>
</div>
<pre class='commit-message'>Use common idiom for converting the UUID.

Wrap lines.</pre>
</li>
</ul>
<h4>2 changed files:</h4>
<ul>
<li class='file-stats'>
<a href='#diff-0'>
src/mailman/rest/members.py
</a>
</li>
<li class='file-stats'>
<a href='#diff-1'>
src/mailman/rest/tests/test_membership.py
</a>
</li>
</ul>
<h4>Changes:</h4>
<li id='diff-0'>
<a href='https://gitlab.com/mailman/mailman/compare/98c074f19492d81ebf5b5c3f4d4f2210aa56230d...06159312d09192b1cede8d20b61ff856442426e8#diff-0'>
 <strong>
src/mailman/rest/members.py
</strong>
</a>
<hr>
<pre class="highlight"><code><span style="color: #000000;background-color: \
#ffdddd">--- a/src/mailman/rest/members.py </span><span style="color: \
#000000;background-color: #ddffdd">+++ b/src/mailman/rest/members.py </span><span \
style="color: #aaaaaa">@@ -107,19 +107,22 @@ class MemberCollection(_MemberBase): \
</span> class AMember(_MemberBase):  """A member."""
 
<span style="color: #000000;background-color: #ffdddd">-    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.
</span><span style="color: #000000;background-color: #ddffdd">+    def __init__(self, \
api, member_id): +        # The member_id is either the member's UUID or the string
+        # representation of the member's UUID.
</span>         self.api = api
<span style="color: #000000;background-color: #ffdddd">-        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)
</span><span style="color: #000000;background-color: #ddffdd">+        self._member = \
None +        service = getUtility(ISubscriptionService)
+        if isinstance(member_id, UUID):
</span>             self._member = service.get_member(member_id)
<span style="color: #000000;background-color: #ddffdd">+        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)
</span> 
     def on_get(self, request, response):
         """Return a single member end-point."""
</code></pre>

<br>
</li>
<li id='diff-1'>
<a href='https://gitlab.com/mailman/mailman/compare/98c074f19492d81ebf5b5c3f4d4f2210aa56230d...06159312d09192b1cede8d20b61ff856442426e8#diff-1'>
 <strong>
src/mailman/rest/tests/test_membership.py
</strong>
</a>
<hr>
<pre class="highlight"><code><span style="color: #000000;background-color: \
#ffdddd">--- a/src/mailman/rest/tests/test_membership.py </span><span style="color: \
#000000;background-color: #ddffdd">+++ b/src/mailman/rest/tests/test_membership.py \
</span><span style="color: #aaaaaa">@@ -518,6 +518,24 @@ class \
TestAPI31Members(unittest.TestCase): </span>             response['address'],
             'http://localhost:9001/3.1/addresses/aperson@example.com')
 
<span style="color: #000000;background-color: #ddffdd">+    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')
+
</span>     def test_cannot_get_member_id_by_int(self):
         with transaction():
             subscribe(self._mlist, 'Anne')
</code></pre>

<br>
</li>

</div>
<div class='footer' style='margin-top: 10px;'>
<p>
&mdash;
<br>
<a href="https://gitlab.com/mailman/mailman/compare/98c074f19492d81ebf5b5c3f4d4f2210aa56230d...06159312d09192b1cede8d20b61ff856442426e8">View \
it on GitLab</a>. <br>
You're receiving this email because of your account on gitlab.com.
If you'd like to receive fewer emails, you can adjust your notification settings.

</p>
</div>
</body>
</html>



_______________________________________________
Mailman-checkins mailing list
Mailman-checkins@python.org
Unsubscribe: https://mail.python.org/mailman/options/mailman-checkins/mailman-cvs%40progressive-comp.com



[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic