summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/mailman/docs/NEWS.rst2
-rw-r--r--src/mailman/rest/docs/domains.rst2
-rw-r--r--src/mailman/rest/docs/lists.rst6
-rw-r--r--src/mailman/rest/lists.py6
-rw-r--r--src/mailman/rest/tests/test_lists.py53
5 files changed, 65 insertions, 4 deletions
diff --git a/src/mailman/docs/NEWS.rst b/src/mailman/docs/NEWS.rst
index 31f00679a..22e988360 100644
--- a/src/mailman/docs/NEWS.rst
+++ b/src/mailman/docs/NEWS.rst
@@ -70,6 +70,8 @@ REST
resources now accept a `held` path component. GETing this returns all held
messages for the mailing list. POSTing to a specific request id under this
url can dispose of the message using `Action` enums.
+ * Mailing list resources now have a `member_count` attribute which gives the
+ number of subscribed members. Given by Toshio Kuratomi.
Interfaces
----------
diff --git a/src/mailman/rest/docs/domains.rst b/src/mailman/rest/docs/domains.rst
index 2fae8f590..c890af7fa 100644
--- a/src/mailman/rest/docs/domains.rst
+++ b/src/mailman/rest/docs/domains.rst
@@ -140,7 +140,9 @@ example.com domain does not contain any mailing lists.
fqdn_listname: test-domains@example.com
http_etag: "..."
...
+ member_count: 0
self_link: http://localhost:9001/3.0/lists/test-domains@example.com
+ volume: 1
http_etag: "..."
start: 0
total_size: 1
diff --git a/src/mailman/rest/docs/lists.rst b/src/mailman/rest/docs/lists.rst
index 135a0374c..610244968 100644
--- a/src/mailman/rest/docs/lists.rst
+++ b/src/mailman/rest/docs/lists.rst
@@ -25,7 +25,9 @@ Create a mailing list in a domain and it's accessible via the API.
http_etag: "..."
list_name: test-one
mail_host: example.com
+ member_count: 0
self_link: http://localhost:9001/3.0/lists/test-one@example.com
+ volume: 1
http_etag: "..."
start: 0
total_size: 1
@@ -40,7 +42,9 @@ You can also query for lists from a particular domain.
http_etag: "..."
list_name: test-one
mail_host: example.com
+ member_count: 0
self_link: http://localhost:9001/3.0/lists/test-one@example.com
+ volume: 1
http_etag: "..."
start: 0
total_size: 1
@@ -87,7 +91,9 @@ It is also available via the location given in the response.
http_etag: "..."
list_name: test-two
mail_host: example.com
+ member_count: 0
self_link: http://localhost:9001/3.0/lists/test-two@example.com
+ volume: 1
However, you are not allowed to create a mailing list in a domain that does
not exist.
diff --git a/src/mailman/rest/lists.py b/src/mailman/rest/lists.py
index 859372fb2..38e2d9841 100644
--- a/src/mailman/rest/lists.py
+++ b/src/mailman/rest/lists.py
@@ -105,10 +105,12 @@ class _ListBase(resource.Resource, CollectionMixin):
def _resource_as_dict(self, mlist):
"""See `CollectionMixin`."""
return dict(
+ display_name=mlist.display_name,
fqdn_listname=mlist.fqdn_listname,
- mail_host=mlist.mail_host,
list_name=mlist.list_name,
- display_name=mlist.display_name,
+ mail_host=mlist.mail_host,
+ member_count=len(tuple(mlist.members.members)),
+ volume=mlist.volume,
self_link=path_to('lists/{0}'.format(mlist.fqdn_listname)),
)
diff --git a/src/mailman/rest/tests/test_lists.py b/src/mailman/rest/tests/test_lists.py
index 78b793c6c..b030a2e8d 100644
--- a/src/mailman/rest/tests/test_lists.py
+++ b/src/mailman/rest/tests/test_lists.py
@@ -17,23 +17,31 @@
"""REST list tests."""
-from __future__ import absolute_import, unicode_literals
+from __future__ import absolute_import, print_function, unicode_literals
__metaclass__ = type
__all__ = [
+ 'TestLists',
+ 'TestListsMissing',
]
import unittest
from urllib2 import HTTPError
+from zope.component import getUtility
+from mailman.app.lifecycle import create_list
+from mailman.config import config
+from mailman.interfaces.usermanager import IUserManager
from mailman.testing.helpers import call_api
from mailman.testing.layers import RESTLayer
-class TestLists(unittest.TestCase):
+class TestListsMissing(unittest.TestCase):
+ """Test expected failures."""
+
layer = RESTLayer
def test_missing_list_roster_member_404(self):
@@ -79,3 +87,44 @@ class TestLists(unittest.TestCase):
self.assertEqual(exc.code, 404)
else:
raise AssertionError('Expected HTTPError')
+
+
+
+class TestLists(unittest.TestCase):
+ """Test various aspects of mailing list resources."""
+
+ layer = RESTLayer
+
+ def setUp(self):
+ self._mlist = create_list('test@example.com')
+ config.db.commit()
+ self._usermanager = getUtility(IUserManager)
+
+ def test_member_count_with_no_members(self):
+ # The list initially has 0 members.
+ resource, response = call_api(
+ 'http://localhost:9001/3.0/lists/test@example.com')
+ self.assertEqual(response.status, 200)
+ self.assertEqual(resource['member_count'], 0)
+
+ def test_member_count_with_one_member(self):
+ # Add a member to a list and check that the resource reflects this.
+ anne = self._usermanager.create_address('anne@example.com')
+ self._mlist.subscribe(anne)
+ config.db.commit()
+ resource, response = call_api(
+ 'http://localhost:9001/3.0/lists/test@example.com')
+ self.assertEqual(response.status, 200)
+ self.assertEqual(resource['member_count'], 1)
+
+ def test_member_count_with_two_members(self):
+ # Add two members to a list and check that the resource reflects this.
+ anne = self._usermanager.create_address('anne@example.com')
+ self._mlist.subscribe(anne)
+ bart = self._usermanager.create_address('bar@example.com')
+ self._mlist.subscribe(bart)
+ config.db.commit()
+ resource, response = call_api(
+ 'http://localhost:9001/3.0/lists/test@example.com')
+ self.assertEqual(response.status, 200)
+ self.assertEqual(resource['member_count'], 2)