~barry/mailman/events-and-web

« back to all changes in this revision

Viewing changes to src/mailman/model/tests/test_domain.py

  • Committer: klm
  • Date: 1998-01-07 21:21:35 UTC
  • Revision ID: vcs-imports@canonical.com-19980107212135-sv0y521ps0xye37r
Initial revision

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2011-2012 by the Free Software Foundation, Inc.
2
 
#
3
 
# This file is part of GNU Mailman.
4
 
#
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)
8
 
# any later version.
9
 
#
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
13
 
# more details.
14
 
#
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/>.
17
 
 
18
 
"""Test domains."""
19
 
 
20
 
from __future__ import absolute_import, unicode_literals
21
 
 
22
 
__metaclass__ = type
23
 
__all__ = [
24
 
    ]
25
 
 
26
 
 
27
 
import unittest
28
 
 
29
 
from zope.component import getUtility
30
 
 
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
38
 
 
39
 
 
40
 
 
41
 
class TestDomainManager(unittest.TestCase):
42
 
    layer = ConfigLayer
43
 
 
44
 
    def setUp(self):
45
 
        self._events = []
46
 
 
47
 
    def _record_event(self, event):
48
 
        self._events.append(event)
49
 
 
50
 
    def test_create_domain_event(self):
51
 
        # Test that creating a domain in the domain manager propagates the
52
 
        # expected events.
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)
60
 
 
61
 
    def test_delete_domain_event(self):
62
 
        # Test that deleting a domain in the domain manager propagates the
63
 
        # expected event.
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')
72
 
 
73
 
 
74
 
 
75
 
class TestDomainLifecycleEvents(unittest.TestCase):
76
 
    layer = ConfigLayer
77
 
 
78
 
    def setUp(self):
79
 
        self._domainmanager = getUtility(IDomainManager)
80
 
        self._org = self._domainmanager.add('example.net')
81
 
        self._net = self._domainmanager.add('example.org')
82
 
 
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
85
 
        # also deleted.
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)