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
=== modified file 'src/mailman/rest/docs/domains.rst'
--- src/mailman/rest/docs/domains.rst 2011-08-31 02:04:14 +0000
+++ src/mailman/rest/docs/domains.rst 2012-03-15 21:46:20 +0000
@@ -139,7 +139,7 @@
139 fqdn_listname: test-domains@example.com139 fqdn_listname: test-domains@example.com
140 http_etag: "..."140 http_etag: "..."
141 ...141 ...
142 self_link: http://localhost:9001/3.0/lists/test-domains@example.com142 volume: 1
143 http_etag: "..."143 http_etag: "..."
144 start: 0144 start: 0
145 total_size: 1145 total_size: 1
146146
=== modified file 'src/mailman/rest/docs/lists.rst'
--- src/mailman/rest/docs/lists.rst 2011-08-31 02:04:14 +0000
+++ src/mailman/rest/docs/lists.rst 2012-03-15 21:46:20 +0000
@@ -24,8 +24,10 @@
24 http_etag: "..."24 http_etag: "..."
25 list_name: test-one25 list_name: test-one
26 mail_host: example.com26 mail_host: example.com
27 member_count: 0
27 real_name: Test-one28 real_name: Test-one
28 self_link: http://localhost:9001/3.0/lists/test-one@example.com29 self_link: http://localhost:9001/3.0/lists/test-one@example.com
30 volume: 1
29 http_etag: "..."31 http_etag: "..."
30 start: 032 start: 0
31 total_size: 133 total_size: 1
@@ -39,8 +41,10 @@
39 http_etag: "..."41 http_etag: "..."
40 list_name: test-one42 list_name: test-one
41 mail_host: example.com43 mail_host: example.com
44 member_count: 0
42 real_name: Test-one45 real_name: Test-one
43 self_link: http://localhost:9001/3.0/lists/test-one@example.com46 self_link: http://localhost:9001/3.0/lists/test-one@example.com
47 volume: 1
44 http_etag: "..."48 http_etag: "..."
45 start: 049 start: 0
46 total_size: 150 total_size: 1
@@ -86,8 +90,10 @@
86 http_etag: "..."90 http_etag: "..."
87 list_name: test-two91 list_name: test-two
88 mail_host: example.com92 mail_host: example.com
93 member_count: 0
89 real_name: Test-two94 real_name: Test-two
90 self_link: http://localhost:9001/3.0/lists/test-two@example.com95 self_link: http://localhost:9001/3.0/lists/test-two@example.com
96 volume: 1
9197
92However, you are not allowed to create a mailing list in a domain that does98However, you are not allowed to create a mailing list in a domain that does
93not exist.99not exist.
94100
=== modified file 'src/mailman/rest/lists.py'
--- src/mailman/rest/lists.py 2012-01-30 15:37:16 +0000
+++ src/mailman/rest/lists.py 2012-03-15 21:46:20 +0000
@@ -109,6 +109,8 @@
109 mail_host=mlist.mail_host,109 mail_host=mlist.mail_host,
110 list_name=mlist.list_name,110 list_name=mlist.list_name,
111 real_name=mlist.real_name,111 real_name=mlist.real_name,
112 member_count=len(tuple(mlist.members.members)),
113 volume=mlist.volume,
112 self_link=path_to('lists/{0}'.format(mlist.fqdn_listname)),114 self_link=path_to('lists/{0}'.format(mlist.fqdn_listname)),
113 )115 )
114116
115117
=== modified file 'src/mailman/rest/tests/test_lists.py'
--- src/mailman/rest/tests/test_lists.py 2012-01-01 19:14:46 +0000
+++ src/mailman/rest/tests/test_lists.py 2012-03-15 21:46:20 +0000
@@ -28,12 +28,17 @@
2828
29from urllib2 import HTTPError29from urllib2 import HTTPError
3030
31from zope.component import getUtility
32
33from mailman.app.lifecycle import create_list
34from mailman.config import config
35from mailman.interfaces.usermanager import IUserManager
31from mailman.testing.helpers import call_api36from mailman.testing.helpers import call_api
32from mailman.testing.layers import RESTLayer37from mailman.testing.layers import RESTLayer
3338
3439
3540
3641
37class TestLists(unittest.TestCase):42class TestListsMissing(unittest.TestCase):
38 layer = RESTLayer43 layer = RESTLayer
3944
40 def test_missing_list_roster_member_404(self):45 def test_missing_list_roster_member_404(self):
@@ -79,3 +84,40 @@
79 self.assertEqual(exc.code, 404)84 self.assertEqual(exc.code, 404)
80 else:85 else:
81 raise AssertionError('Expected HTTPError')86 raise AssertionError('Expected HTTPError')
87
88class TestLists(unittest.TestCase):
89 layer = RESTLayer
90
91 def setUp(self):
92 self._mlist = create_list('test@example.com')
93 config.db.commit()
94 self._usermanager = getUtility(IUserManager)
95
96 def test_list_members_count(self):
97 # The list initially has 0 members
98 list_info, response = call_api('http://localhost:9001/3.0/lists/test@example.com')
99 if response.status != 200:
100 raise AssertionError('Got an error from rest server: {0}'.format(response.status))
101 self.assertEqual(list_info['member_count'], 0)
102
103 # Add a member to a list
104 alice = self._usermanager.create_address('alice@example.com')
105 self._mlist.subscribe(alice)
106 config.db.commit()
107
108 # Make sure that the api returns one member now
109 list_info, response = call_api('http://localhost:9001/3.0/lists/test@example.com')
110 if response.status != 200:
111 raise AssertionError('Got an error from rest server: {0}'.format(response.status))
112 self.assertEqual(list_info['member_count'], 1)
113
114 # Add a second member to it
115 bob = self._usermanager.create_address('bob@example.com')
116 self._mlist.subscribe(bob)
117 config.db.commit()
118
119 # Make sure that the api returns two members now
120 list_info, response = call_api('http://localhost:9001/3.0/lists/test@example.com')
121 if response.status != 200:
122 raise AssertionError('Got an error from rest server: {0}'.format(response.status))
123 self.assertEqual(list_info['member_count'], 2)