summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mailman/interfaces/listmanager.py16
-rw-r--r--src/mailman/model/listmanager.py7
-rw-r--r--src/mailman/model/tests/test_listmanager.py71
-rw-r--r--src/mailman/model/tests/test_user.py4
4 files changed, 95 insertions, 3 deletions
diff --git a/src/mailman/interfaces/listmanager.py b/src/mailman/interfaces/listmanager.py
index 1efb4342f..3038be02b 100644
--- a/src/mailman/interfaces/listmanager.py
+++ b/src/mailman/interfaces/listmanager.py
@@ -23,6 +23,8 @@ __metaclass__ = type
__all__ = [
'IListManager',
'ListAlreadyExistsError',
+ 'ListCreatedEvent',
+ 'ListDeletedEvent',
'NoSuchListError',
]
@@ -51,6 +53,20 @@ class NoSuchListError(MailmanError):
return 'No such mailing list: {0.fqdn_listname}'.format(self)
+class ListCreatedEvent:
+ """A mailing list was created."""
+
+ def __init__(self, mlist):
+ self.mailing_list = mlist
+
+
+class ListDeletedEvent:
+ """A mailing list was deleted."""
+
+ def __init__(self, fqdn_listname):
+ self.fqdn_listname = fqdn_listname
+
+
class IListManager(Interface):
diff --git a/src/mailman/model/listmanager.py b/src/mailman/model/listmanager.py
index a7f302883..8c3fc9421 100644
--- a/src/mailman/model/listmanager.py
+++ b/src/mailman/model/listmanager.py
@@ -27,11 +27,13 @@ __all__ = [
import datetime
+from zope.event import notify
from zope.interface import implements
from mailman.config import config
from mailman.interfaces.address import InvalidEmailAddressError
-from mailman.interfaces.listmanager import IListManager, ListAlreadyExistsError
+from mailman.interfaces.listmanager import (
+ IListManager, ListAlreadyExistsError, ListCreatedEvent, ListDeletedEvent)
from mailman.model.mailinglist import MailingList
@@ -55,6 +57,7 @@ class ListManager:
mlist = MailingList(fqdn_listname)
mlist.created_at = datetime.datetime.now()
config.db.store.add(mlist)
+ notify(ListCreatedEvent(mlist))
return mlist
def get(self, fqdn_listname):
@@ -70,7 +73,9 @@ class ListManager:
def delete(self, mlist):
"""See `IListManager`."""
+ fqdn_listname = mlist.fqdn_listname
config.db.store.remove(mlist)
+ notify(ListDeletedEvent(fqdn_listname))
@property
def mailing_lists(self):
diff --git a/src/mailman/model/tests/test_listmanager.py b/src/mailman/model/tests/test_listmanager.py
new file mode 100644
index 000000000..f7caccdb0
--- /dev/null
+++ b/src/mailman/model/tests/test_listmanager.py
@@ -0,0 +1,71 @@
+# Copyright (C) 2011 by the Free Software Foundation, Inc.
+#
+# This file is part of GNU Mailman.
+#
+# GNU Mailman is free software: you can redistribute it and/or modify it under
+# the terms of the GNU General Public License as published by the Free
+# Software Foundation, either version 3 of the License, or (at your option)
+# any later version.
+#
+# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
+# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+# more details.
+#
+# You should have received a copy of the GNU General Public License along with
+# GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
+
+"""Test the ListManager."""
+
+from __future__ import absolute_import, unicode_literals
+
+__metaclass__ = type
+__all__ = [
+ 'test_suite',
+ ]
+
+
+import unittest
+
+from zope.component import getUtility
+
+from mailman.app.lifecycle import create_list
+from mailman.interfaces.listmanager import (
+ IListManager, ListCreatedEvent, ListDeletedEvent)
+from mailman.testing.helpers import event_subscribers
+from mailman.testing.layers import ConfigLayer
+
+
+
+class TestListManager(unittest.TestCase):
+ layer = ConfigLayer
+
+ def setUp(self):
+ self._event = None
+
+ def _record_event(self, event):
+ self._event = event
+
+ def test_create_list_event(self):
+ # Test that creating a list in the list manager propagates the
+ # expected event.
+ with event_subscribers(self._record_event):
+ mlist = getUtility(IListManager).create('test@example.com')
+ self.assertTrue(isinstance(self._event, ListCreatedEvent))
+ self.assertEqual(self._event.mailing_list, mlist)
+
+ def test_delete_list_event(self):
+ # Test that deleting a list in the list manager propagates the
+ # expected event.
+ mlist = create_list('another@example.com')
+ with event_subscribers(self._record_event):
+ getUtility(IListManager).delete(mlist)
+ self.assertTrue(isinstance(self._event, ListDeletedEvent))
+ self.assertEqual(self._event.fqdn_listname, 'another@example.com')
+
+
+
+def test_suite():
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.makeSuite(TestListManager))
+ return suite
diff --git a/src/mailman/model/tests/test_user.py b/src/mailman/model/tests/test_user.py
index 072b2f7be..4112572bd 100644
--- a/src/mailman/model/tests/test_user.py
+++ b/src/mailman/model/tests/test_user.py
@@ -27,13 +27,13 @@ __all__ = [
import unittest
+from zope.component import getUtility
+
from mailman.app.lifecycle import create_list
from mailman.interfaces.usermanager import IUserManager
from mailman.testing.layers import ConfigLayer
from mailman.utilities.datetime import now
-from zope.component import getUtility
-
class TestUser(unittest.TestCase):