summaryrefslogtreecommitdiff
path: root/src/mailman/model/tests/test_domain.py
diff options
context:
space:
mode:
authorBarry Warsaw2011-09-02 14:48:48 -0400
committerBarry Warsaw2011-09-02 14:48:48 -0400
commit340c25de0f8fdd2c4093cf233cd4e999bff52856 (patch)
tree995dfe1ea558d7ce9e8431d0b8d47c4e6c6486ac /src/mailman/model/tests/test_domain.py
parent782f001439572794992e1687dbdacec6f2faa263 (diff)
downloadmailman-340c25de0f8fdd2c4093cf233cd4e999bff52856.tar.gz
mailman-340c25de0f8fdd2c4093cf233cd4e999bff52856.tar.zst
mailman-340c25de0f8fdd2c4093cf233cd4e999bff52856.zip
* Four new events are created, and notifications are sent during domain
lifecycle changes: - DomainCreatingEvent - sent before the domain is created - DomainCreatedEvent - sent after the domain is created - DomainDeletingEvent - sent before the domain is deleted - DomainDeletedEvent - sent after the domain is deleted * Using the above events, when a domain is deleted, associated mailing lists are deleted. (LP: #837526)
Diffstat (limited to 'src/mailman/model/tests/test_domain.py')
-rw-r--r--src/mailman/model/tests/test_domain.py113
1 files changed, 113 insertions, 0 deletions
diff --git a/src/mailman/model/tests/test_domain.py b/src/mailman/model/tests/test_domain.py
new file mode 100644
index 000000000..4ad8a5403
--- /dev/null
+++ b/src/mailman/model/tests/test_domain.py
@@ -0,0 +1,113 @@
+# 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 domains."""
+
+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.domain import (
+ DomainCreatedEvent, DomainCreatingEvent, DomainDeletedEvent,
+ DomainDeletingEvent, IDomainManager)
+from mailman.interfaces.listmanager import IListManager
+from mailman.testing.helpers import event_subscribers
+from mailman.testing.layers import ConfigLayer
+
+
+
+class TestDomainManager(unittest.TestCase):
+ layer = ConfigLayer
+
+ def setUp(self):
+ self._events = []
+
+ def _record_event(self, event):
+ self._events.append(event)
+
+ def test_create_domain_event(self):
+ # Test that creating a domain in the domain manager propagates the
+ # expected events.
+ with event_subscribers(self._record_event):
+ domain = getUtility(IDomainManager).add('example.org')
+ self.assertEqual(len(self._events), 2)
+ self.assertTrue(isinstance(self._events[0], DomainCreatingEvent))
+ self.assertEqual(self._events[0].mail_host, 'example.org')
+ self.assertTrue(isinstance(self._events[1], DomainCreatedEvent))
+ self.assertEqual(self._events[1].domain, domain)
+
+ def test_delete_domain_event(self):
+ # Test that deleting a domain in the domain manager propagates the
+ # expected event.
+ domain = getUtility(IDomainManager).add('example.org')
+ with event_subscribers(self._record_event):
+ getUtility(IDomainManager).remove('example.org')
+ self.assertEqual(len(self._events), 2)
+ self.assertTrue(isinstance(self._events[0], DomainDeletingEvent))
+ self.assertEqual(self._events[0].domain, domain)
+ self.assertTrue(isinstance(self._events[1], DomainDeletedEvent))
+ self.assertEqual(self._events[1].mail_host, 'example.org')
+
+
+
+class TestDomainLifecycleEvents(unittest.TestCase):
+ layer = ConfigLayer
+
+ def setUp(self):
+ self._domainmanager = getUtility(IDomainManager)
+ self._org = self._domainmanager.add('example.net')
+ self._net = self._domainmanager.add('example.org')
+
+ def test_lists_are_deleted_when_domain_is_deleted(self):
+ # When a domain is deleted, all the mailing lists in that domain are
+ # also deleted.
+ create_list('ant@example.net')
+ create_list('bee@example.net')
+ cat = create_list('cat@example.org')
+ dog = create_list('dog@example.org')
+ ewe = create_list('ewe@example.com')
+ fly = create_list('fly@example.com')
+ listmanager = getUtility(IListManager)
+ self._domainmanager.remove('example.net')
+ self.assertEqual(listmanager.get('ant@example.net'), None)
+ self.assertEqual(listmanager.get('bee@example.net'), None)
+ self.assertEqual(listmanager.get('cat@example.org'), cat)
+ self.assertEqual(listmanager.get('dog@example.org'), dog)
+ self.assertEqual(listmanager.get('ewe@example.com'), ewe)
+ self.assertEqual(listmanager.get('fly@example.com'), fly)
+ self._domainmanager.remove('example.org')
+ self.assertEqual(listmanager.get('cat@example.org'), None)
+ self.assertEqual(listmanager.get('dog@example.org'), None)
+ self.assertEqual(listmanager.get('ewe@example.com'), ewe)
+ self.assertEqual(listmanager.get('fly@example.com'), fly)
+
+
+
+def test_suite():
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.makeSuite(TestDomainManager))
+ suite.addTest(unittest.makeSuite(TestDomainLifecycleEvents))
+ return suite