1
# Copyright (C) 2011-2012 by the Free Software Foundation, Inc.
3
# This file is part of GNU Mailman.
5
# GNU Mailman is free software: you can redistribute it and/or modify it under
6
# the terms of the GNU General Public License as published by the Free
7
# Software Foundation, either version 3 of the License, or (at your option)
10
# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
11
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15
# You should have received a copy of the GNU General Public License along with
16
# GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
20
from __future__ import absolute_import, unicode_literals
29
from zope.component import getUtility
31
from mailman.app.lifecycle import create_list
32
from mailman.interfaces.domain import (
33
DomainCreatedEvent, DomainCreatingEvent, DomainDeletedEvent,
34
DomainDeletingEvent, IDomainManager)
35
from mailman.interfaces.listmanager import IListManager
36
from mailman.testing.helpers import event_subscribers
37
from mailman.testing.layers import ConfigLayer
41
class TestDomainManager(unittest.TestCase):
47
def _record_event(self, event):
48
self._events.append(event)
50
def test_create_domain_event(self):
51
# Test that creating a domain in the domain manager propagates the
53
with event_subscribers(self._record_event):
54
domain = getUtility(IDomainManager).add('example.org')
55
self.assertEqual(len(self._events), 2)
56
self.assertTrue(isinstance(self._events[0], DomainCreatingEvent))
57
self.assertEqual(self._events[0].mail_host, 'example.org')
58
self.assertTrue(isinstance(self._events[1], DomainCreatedEvent))
59
self.assertEqual(self._events[1].domain, domain)
61
def test_delete_domain_event(self):
62
# Test that deleting a domain in the domain manager propagates the
64
domain = getUtility(IDomainManager).add('example.org')
65
with event_subscribers(self._record_event):
66
getUtility(IDomainManager).remove('example.org')
67
self.assertEqual(len(self._events), 2)
68
self.assertTrue(isinstance(self._events[0], DomainDeletingEvent))
69
self.assertEqual(self._events[0].domain, domain)
70
self.assertTrue(isinstance(self._events[1], DomainDeletedEvent))
71
self.assertEqual(self._events[1].mail_host, 'example.org')
75
class TestDomainLifecycleEvents(unittest.TestCase):
79
self._domainmanager = getUtility(IDomainManager)
80
self._org = self._domainmanager.add('example.net')
81
self._net = self._domainmanager.add('example.org')
83
def test_lists_are_deleted_when_domain_is_deleted(self):
84
# When a domain is deleted, all the mailing lists in that domain are
86
create_list('ant@example.net')
87
create_list('bee@example.net')
88
cat = create_list('cat@example.org')
89
dog = create_list('dog@example.org')
90
ewe = create_list('ewe@example.com')
91
fly = create_list('fly@example.com')
92
listmanager = getUtility(IListManager)
93
self._domainmanager.remove('example.net')
94
self.assertEqual(listmanager.get('ant@example.net'), None)
95
self.assertEqual(listmanager.get('bee@example.net'), None)
96
self.assertEqual(listmanager.get('cat@example.org'), cat)
97
self.assertEqual(listmanager.get('dog@example.org'), dog)
98
self.assertEqual(listmanager.get('ewe@example.com'), ewe)
99
self.assertEqual(listmanager.get('fly@example.com'), fly)
100
self._domainmanager.remove('example.org')
101
self.assertEqual(listmanager.get('cat@example.org'), None)
102
self.assertEqual(listmanager.get('dog@example.org'), None)
103
self.assertEqual(listmanager.get('ewe@example.com'), ewe)
104
self.assertEqual(listmanager.get('fly@example.com'), fly)