Merge lp:~toshio/mailman/count into lp:mailman

Proposed by Toshio Kuratomi
Status: Merged
Approved by: Barry Warsaw
Approved revision: 7119
Merged at revision: 7120
Proposed branch: lp:~toshio/mailman/count
Merge into: lp:mailman
Diff against target: 126 lines (+52/-2)
4 files modified
src/mailman/rest/docs/domains.rst (+1/-1)
src/mailman/rest/docs/lists.rst (+6/-0)
src/mailman/rest/lists.py (+2/-0)
src/mailman/rest/tests/test_lists.py (+43/-1)
To merge this branch: bzr merge lp:~toshio/mailman/count
Reviewer Review Type Date Requested Status
Barry Warsaw Approve
Review via email: mp+97576@code.launchpad.net

Description of the change

Expose the volume and count of members per mailing list in the rest api.

To post a comment you must log in.
Revision history for this message
Barry Warsaw (barry) wrote :

Looks great! Another useful test (and it can be a unittest or doctest) would be to show that adding new members (probably behind the scenes) changes that members value. I'll mark this needs fixing for now, but that should be a pretty easy test to add.

As discussed at the sprint, we can make this more efficient later by adding an API to IRoster, but don't worry about that for this branch.

review: Needs Fixing
lp:~toshio/mailman/count updated
7118. By toshio <email address hidden>

Merge upstream

7119. By toshio <email address hidden>

Unittest to show that adding members to a list is reflected in the rest api

Revision history for this message
Barry Warsaw (barry) wrote :

Looks great, thanks. I'll make the one change that checks response.status == 200 via self.assertEquals().

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/mailman/rest/docs/domains.rst'
2--- src/mailman/rest/docs/domains.rst 2011-08-31 02:04:14 +0000
3+++ src/mailman/rest/docs/domains.rst 2012-03-15 21:46:20 +0000
4@@ -139,7 +139,7 @@
5 fqdn_listname: test-domains@example.com
6 http_etag: "..."
7 ...
8- self_link: http://localhost:9001/3.0/lists/test-domains@example.com
9+ volume: 1
10 http_etag: "..."
11 start: 0
12 total_size: 1
13
14=== modified file 'src/mailman/rest/docs/lists.rst'
15--- src/mailman/rest/docs/lists.rst 2011-08-31 02:04:14 +0000
16+++ src/mailman/rest/docs/lists.rst 2012-03-15 21:46:20 +0000
17@@ -24,8 +24,10 @@
18 http_etag: "..."
19 list_name: test-one
20 mail_host: example.com
21+ member_count: 0
22 real_name: Test-one
23 self_link: http://localhost:9001/3.0/lists/test-one@example.com
24+ volume: 1
25 http_etag: "..."
26 start: 0
27 total_size: 1
28@@ -39,8 +41,10 @@
29 http_etag: "..."
30 list_name: test-one
31 mail_host: example.com
32+ member_count: 0
33 real_name: Test-one
34 self_link: http://localhost:9001/3.0/lists/test-one@example.com
35+ volume: 1
36 http_etag: "..."
37 start: 0
38 total_size: 1
39@@ -86,8 +90,10 @@
40 http_etag: "..."
41 list_name: test-two
42 mail_host: example.com
43+ member_count: 0
44 real_name: Test-two
45 self_link: http://localhost:9001/3.0/lists/test-two@example.com
46+ volume: 1
47
48 However, you are not allowed to create a mailing list in a domain that does
49 not exist.
50
51=== modified file 'src/mailman/rest/lists.py'
52--- src/mailman/rest/lists.py 2012-01-30 15:37:16 +0000
53+++ src/mailman/rest/lists.py 2012-03-15 21:46:20 +0000
54@@ -109,6 +109,8 @@
55 mail_host=mlist.mail_host,
56 list_name=mlist.list_name,
57 real_name=mlist.real_name,
58+ member_count=len(tuple(mlist.members.members)),
59+ volume=mlist.volume,
60 self_link=path_to('lists/{0}'.format(mlist.fqdn_listname)),
61 )
62
63
64=== modified file 'src/mailman/rest/tests/test_lists.py'
65--- src/mailman/rest/tests/test_lists.py 2012-01-01 19:14:46 +0000
66+++ src/mailman/rest/tests/test_lists.py 2012-03-15 21:46:20 +0000
67@@ -28,12 +28,17 @@
68
69 from urllib2 import HTTPError
70
71+from zope.component import getUtility
72+
73+from mailman.app.lifecycle import create_list
74+from mailman.config import config
75+from mailman.interfaces.usermanager import IUserManager
76 from mailman.testing.helpers import call_api
77 from mailman.testing.layers import RESTLayer
78
79
80
81
82-class TestLists(unittest.TestCase):
83+class TestListsMissing(unittest.TestCase):
84 layer = RESTLayer
85
86 def test_missing_list_roster_member_404(self):
87@@ -79,3 +84,40 @@
88 self.assertEqual(exc.code, 404)
89 else:
90 raise AssertionError('Expected HTTPError')
91+
92+class TestLists(unittest.TestCase):
93+ layer = RESTLayer
94+
95+ def setUp(self):
96+ self._mlist = create_list('test@example.com')
97+ config.db.commit()
98+ self._usermanager = getUtility(IUserManager)
99+
100+ def test_list_members_count(self):
101+ # The list initially has 0 members
102+ list_info, response = call_api('http://localhost:9001/3.0/lists/test@example.com')
103+ if response.status != 200:
104+ raise AssertionError('Got an error from rest server: {0}'.format(response.status))
105+ self.assertEqual(list_info['member_count'], 0)
106+
107+ # Add a member to a list
108+ alice = self._usermanager.create_address('alice@example.com')
109+ self._mlist.subscribe(alice)
110+ config.db.commit()
111+
112+ # Make sure that the api returns one member now
113+ list_info, response = call_api('http://localhost:9001/3.0/lists/test@example.com')
114+ if response.status != 200:
115+ raise AssertionError('Got an error from rest server: {0}'.format(response.status))
116+ self.assertEqual(list_info['member_count'], 1)
117+
118+ # Add a second member to it
119+ bob = self._usermanager.create_address('bob@example.com')
120+ self._mlist.subscribe(bob)
121+ config.db.commit()
122+
123+ # Make sure that the api returns two members now
124+ list_info, response = call_api('http://localhost:9001/3.0/lists/test@example.com')
125+ if response.status != 200:
126+ raise AssertionError('Got an error from rest server: {0}'.format(response.status))
127+ self.assertEqual(list_info['member_count'], 2)