Import order flake8 plugin.
[mailman.git] / src / mailman / app / tests / test_lifecycle.py
bloba3a186f6fa20590b5095babe26a0a47cc4ab6116
1 # Copyright (C) 2012-2016 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)
8 # any later version.
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.
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/>.
18 """Test the high level list lifecycle API."""
20 import os
21 import shutil
22 import unittest
24 from mailman.app.lifecycle import create_list, remove_list
25 from mailman.interfaces.address import InvalidEmailAddressError
26 from mailman.interfaces.domain import BadDomainSpecificationError
27 from mailman.interfaces.listmanager import IListManager
28 from mailman.testing.layers import ConfigLayer
29 from zope.component import getUtility
32 class TestLifecycle(unittest.TestCase):
33 """Test the high level list lifecycle API."""
35 layer = ConfigLayer
37 def test_posting_address_validation(self):
38 # Creating a mailing list with a bogus address raises an exception.
39 self.assertRaises(InvalidEmailAddressError,
40 create_list, 'bogus address')
42 def test_unregistered_domain(self):
43 # Creating a list with an unregistered domain raises an exception.
44 self.assertRaises(BadDomainSpecificationError,
45 create_list, 'test@nodomain.example.org')
47 def test_remove_list_error(self):
48 # An error occurs while deleting the list's data directory.
49 mlist = create_list('test@example.com')
50 os.chmod(mlist.data_path, 0)
51 self.addCleanup(shutil.rmtree, mlist.data_path)
52 self.assertRaises(OSError, remove_list, mlist)
53 os.chmod(mlist.data_path, 0o777)
55 def test_create_no_such_style(self):
56 mlist = create_list('ant@example.com', style_name='bogus')
57 # The MailmanList._preferred_language column isn't set so there's no
58 # valid mapping to an ILanguage. Therefore this call will produce a
59 # KeyError.
60 self.assertRaises(KeyError, getattr, mlist, 'preferred_language')
62 def test_remove_list_without_data_path(self):
63 mlist = create_list('ant@example.com')
64 shutil.rmtree(mlist.data_path)
65 remove_list(mlist)
66 self.assertIsNone(getUtility(IListManager).get('ant@example.com'))