summaryrefslogtreecommitdiff
path: root/src/mailman/app/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/mailman/app/tests')
-rw-r--r--src/mailman/app/tests/test_bounces.py5
-rw-r--r--src/mailman/app/tests/test_inject.py2
-rw-r--r--src/mailman/app/tests/test_lifecycle.py16
-rw-r--r--src/mailman/app/tests/test_membership.py43
-rw-r--r--src/mailman/app/tests/test_moderation.py2
-rw-r--r--src/mailman/app/tests/test_notifications.py44
-rw-r--r--src/mailman/app/tests/test_registration.py132
-rw-r--r--src/mailman/app/tests/test_subscriptions.py2
-rw-r--r--src/mailman/app/tests/test_templates.py2
9 files changed, 220 insertions, 28 deletions
diff --git a/src/mailman/app/tests/test_bounces.py b/src/mailman/app/tests/test_bounces.py
index f6d5669a4..5eb518786 100644
--- a/src/mailman/app/tests/test_bounces.py
+++ b/src/mailman/app/tests/test_bounces.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2011-2013 by the Free Software Foundation, Inc.
+# Copyright (C) 2011-2014 by the Free Software Foundation, Inc.
#
# This file is part of GNU Mailman.
#
@@ -198,6 +198,7 @@ class TestSendProbe(unittest.TestCase):
def setUp(self):
self._mlist = create_list('test@example.com')
+ self._mlist.send_welcome_message = False
self._member = add_member(self._mlist, 'anne@example.com',
'Anne Person', 'xxx',
DeliveryMode.regular, 'en')
@@ -355,6 +356,7 @@ class TestProbe(unittest.TestCase):
def setUp(self):
self._mlist = create_list('test@example.com')
+ self._mlist.send_welcome_message = False
self._member = add_member(self._mlist, 'anne@example.com',
'Anne Person', 'xxx',
DeliveryMode.regular, 'en')
@@ -395,6 +397,7 @@ class TestMaybeForward(unittest.TestCase):
site_owner: postmaster@example.com
""")
self._mlist = create_list('test@example.com')
+ self._mlist.send_welcome_message = False
self._msg = mfs("""\
From: bouncer@example.com
To: test-bounces@example.com
diff --git a/src/mailman/app/tests/test_inject.py b/src/mailman/app/tests/test_inject.py
index 78204aae3..f7f750662 100644
--- a/src/mailman/app/tests/test_inject.py
+++ b/src/mailman/app/tests/test_inject.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2011-2013 by the Free Software Foundation, Inc.
+# Copyright (C) 2011-2014 by the Free Software Foundation, Inc.
#
# This file is part of GNU Mailman.
#
diff --git a/src/mailman/app/tests/test_lifecycle.py b/src/mailman/app/tests/test_lifecycle.py
index cea06359d..0fb54f193 100644
--- a/src/mailman/app/tests/test_lifecycle.py
+++ b/src/mailman/app/tests/test_lifecycle.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 by the Free Software Foundation, Inc.
+# Copyright (C) 2012-2014 by the Free Software Foundation, Inc.
#
# This file is part of GNU Mailman.
#
@@ -25,11 +25,14 @@ __all__ = [
]
+import os
+import shutil
import unittest
+from mailman.config import config
from mailman.interfaces.address import InvalidEmailAddressError
from mailman.interfaces.domain import BadDomainSpecificationError
-from mailman.app.lifecycle import create_list
+from mailman.app.lifecycle import create_list, remove_list
from mailman.testing.layers import ConfigLayer
@@ -48,3 +51,12 @@ class TestLifecycle(unittest.TestCase):
# Creating a list with an unregistered domain raises an exception.
self.assertRaises(BadDomainSpecificationError,
create_list, 'test@nodomain.example.org')
+
+ def test_remove_list_error(self):
+ # An error occurs while deleting the list's data directory.
+ mlist = create_list('test@example.com')
+ data_dir = os.path.join(config.LIST_DATA_DIR, mlist.fqdn_listname)
+ os.chmod(data_dir, 0)
+ self.addCleanup(shutil.rmtree, data_dir)
+ self.assertRaises(OSError, remove_list, mlist)
+ os.chmod(data_dir, 0o777)
diff --git a/src/mailman/app/tests/test_membership.py b/src/mailman/app/tests/test_membership.py
index 07994f34d..95e8de1d0 100644
--- a/src/mailman/app/tests/test_membership.py
+++ b/src/mailman/app/tests/test_membership.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2011-2013 by the Free Software Foundation, Inc.
+# Copyright (C) 2011-2014 by the Free Software Foundation, Inc.
#
# This file is part of GNU Mailman.
#
@@ -17,10 +17,13 @@
"""Tests of application level membership functions."""
-from __future__ import absolute_import, unicode_literals
+from __future__ import absolute_import, print_function, unicode_literals
__metaclass__ = type
__all__ = [
+ 'TestAddMember',
+ 'TestAddMemberPassword',
+ 'TestDeleteMember',
]
@@ -29,17 +32,18 @@ import unittest
from zope.component import getUtility
from mailman.app.lifecycle import create_list
-from mailman.app.membership import add_member
+from mailman.app.membership import add_member, delete_member
from mailman.core.constants import system_preferences
from mailman.interfaces.bans import IBanManager
from mailman.interfaces.member import (
- AlreadySubscribedError, DeliveryMode, MemberRole, MembershipIsBannedError)
+ AlreadySubscribedError, DeliveryMode, MemberRole, MembershipIsBannedError,
+ NotAMemberError)
from mailman.interfaces.usermanager import IUserManager
from mailman.testing.layers import ConfigLayer
-class AddMemberTest(unittest.TestCase):
+class TestAddMember(unittest.TestCase):
layer = ConfigLayer
def setUp(self):
@@ -70,10 +74,13 @@ class AddMemberTest(unittest.TestCase):
# Test that members who are banned by specific address cannot
# subscribe to the mailing list.
IBanManager(self._mlist).ban('anne@example.com')
- self.assertRaises(
- MembershipIsBannedError,
- add_member, self._mlist, 'anne@example.com', 'Anne Person',
- '123', DeliveryMode.regular, system_preferences.preferred_language)
+ with self.assertRaises(MembershipIsBannedError) as cm:
+ add_member(self._mlist, 'anne@example.com', 'Anne Person',
+ '123', DeliveryMode.regular,
+ system_preferences.preferred_language)
+ self.assertEqual(
+ str(cm.exception),
+ 'anne@example.com is not allowed to subscribe to test@example.com')
def test_add_member_globally_banned(self):
# Test that members who are banned by specific address cannot
@@ -165,7 +172,7 @@ class AddMemberTest(unittest.TestCase):
-class AddMemberPasswordTest(unittest.TestCase):
+class TestAddMemberPassword(unittest.TestCase):
layer = ConfigLayer
def setUp(self):
@@ -177,3 +184,19 @@ class AddMemberPasswordTest(unittest.TestCase):
'Anne Person', 'abc', DeliveryMode.regular,
system_preferences.preferred_language)
self.assertEqual(member.user.password, '{plaintext}abc')
+
+
+
+class TestDeleteMember(unittest.TestCase):
+ layer = ConfigLayer
+
+ def setUp(self):
+ self._mlist = create_list('test@example.com')
+
+ def test_delete_member_not_a_member(self):
+ # Try to delete an address which is not a member of the mailing list.
+ with self.assertRaises(NotAMemberError) as cm:
+ delete_member(self._mlist, 'noperson@example.com')
+ self.assertEqual(
+ str(cm.exception),
+ 'noperson@example.com is not a member of test@example.com')
diff --git a/src/mailman/app/tests/test_moderation.py b/src/mailman/app/tests/test_moderation.py
index 529116d35..edb6b8c28 100644
--- a/src/mailman/app/tests/test_moderation.py
+++ b/src/mailman/app/tests/test_moderation.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2011-2013 by the Free Software Foundation, Inc.
+# Copyright (C) 2011-2014 by the Free Software Foundation, Inc.
#
# This file is part of GNU Mailman.
#
diff --git a/src/mailman/app/tests/test_notifications.py b/src/mailman/app/tests/test_notifications.py
index e49228d0a..4cdc1c01c 100644
--- a/src/mailman/app/tests/test_notifications.py
+++ b/src/mailman/app/tests/test_notifications.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 by the Free Software Foundation, Inc.
+# Copyright (C) 2012-2014 by the Free Software Foundation, Inc.
#
# This file is part of GNU Mailman.
#
@@ -33,10 +33,9 @@ from zope.component import getUtility
from mailman.app.lifecycle import create_list
from mailman.app.membership import add_member
-from mailman.app.notifications import send_welcome_message
from mailman.config import config
from mailman.interfaces.languages import ILanguageManager
-from mailman.interfaces.member import DeliveryMode
+from mailman.interfaces.member import DeliveryMode, MemberRole
from mailman.testing.helpers import get_queue_messages
from mailman.testing.layers import ConfigLayer
@@ -82,11 +81,8 @@ Welcome to the $list_name mailing list.
shutil.rmtree(self.var_dir)
def test_welcome_message(self):
- en = getUtility(ILanguageManager).get('en')
add_member(self._mlist, 'anne@example.com', 'Anne Person',
'password', DeliveryMode.regular, 'en')
- send_welcome_message(self._mlist, 'anne@example.com', en,
- DeliveryMode.regular)
# Now there's one message in the virgin queue.
messages = get_queue_messages('virgin')
self.assertEqual(len(messages), 1)
@@ -110,16 +106,42 @@ Welcome to the Test List mailing list.
'mailman:///$listname/$language/welcome.txt')
# Add the xx language and subscribe Anne using it.
manager = getUtility(ILanguageManager)
- xx = manager.add('xx', 'us-ascii', 'Xlandia')
+ manager.add('xx', 'us-ascii', 'Xlandia')
add_member(self._mlist, 'anne@example.com', 'Anne Person',
'password', DeliveryMode.regular, 'xx')
- send_welcome_message(self._mlist, 'anne@example.com', xx,
- DeliveryMode.regular)
# Now there's one message in the virgin queue.
messages = get_queue_messages('virgin')
self.assertEqual(len(messages), 1)
message = messages[0].msg
self.assertEqual(str(message['subject']),
'Welcome to the "Test List" mailing list')
- self.assertEqual(message.get_payload(),
- 'You just joined the Test List mailing list!')
+ self.assertMultiLineEqual(
+ message.get_payload(),
+ 'You just joined the Test List mailing list!')
+
+ def test_no_welcome_message_to_owners(self):
+ # Welcome messages go only to mailing list members, not to owners.
+ add_member(self._mlist, 'anne@example.com', 'Anne Person',
+ 'password', DeliveryMode.regular, 'xx',
+ MemberRole.owner)
+ # There is no welcome message in the virgin queue.
+ messages = get_queue_messages('virgin')
+ self.assertEqual(len(messages), 0)
+
+ def test_no_welcome_message_to_nonmembers(self):
+ # Welcome messages go only to mailing list members, not to nonmembers.
+ add_member(self._mlist, 'anne@example.com', 'Anne Person',
+ 'password', DeliveryMode.regular, 'xx',
+ MemberRole.nonmember)
+ # There is no welcome message in the virgin queue.
+ messages = get_queue_messages('virgin')
+ self.assertEqual(len(messages), 0)
+
+ def test_no_welcome_message_to_moderators(self):
+ # Welcome messages go only to mailing list members, not to moderators.
+ add_member(self._mlist, 'anne@example.com', 'Anne Person',
+ 'password', DeliveryMode.regular, 'xx',
+ MemberRole.moderator)
+ # There is no welcome message in the virgin queue.
+ messages = get_queue_messages('virgin')
+ self.assertEqual(len(messages), 0)
diff --git a/src/mailman/app/tests/test_registration.py b/src/mailman/app/tests/test_registration.py
new file mode 100644
index 000000000..ff128ae6f
--- /dev/null
+++ b/src/mailman/app/tests/test_registration.py
@@ -0,0 +1,132 @@
+# Copyright (C) 2012 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 email address registration."""
+
+from __future__ import absolute_import, print_function, unicode_literals
+
+__metaclass__ = type
+__all__ = [
+ 'TestEmailValidation',
+ 'TestRegistration',
+ ]
+
+
+import unittest
+
+from zope.component import getUtility
+
+from mailman.app.lifecycle import create_list
+from mailman.interfaces.address import InvalidEmailAddressError
+from mailman.interfaces.pending import IPendings
+from mailman.interfaces.registrar import ConfirmationNeededEvent, IRegistrar
+from mailman.testing.helpers import event_subscribers
+from mailman.testing.layers import ConfigLayer
+
+
+
+class TestEmailValidation(unittest.TestCase):
+ """Test basic email validation."""
+
+ layer = ConfigLayer
+
+ def setUp(self):
+ self.registrar = getUtility(IRegistrar)
+ self.mlist = create_list('alpha@example.com')
+
+ def test_empty_string_is_invalid(self):
+ self.assertRaises(InvalidEmailAddressError,
+ self.registrar.register, self.mlist,
+ '')
+
+ def test_no_spaces_allowed(self):
+ self.assertRaises(InvalidEmailAddressError,
+ self.registrar.register, self.mlist,
+ 'some name@example.com')
+
+ def test_no_angle_brackets(self):
+ self.assertRaises(InvalidEmailAddressError,
+ self.registrar.register, self.mlist,
+ '<script>@example.com')
+
+ def test_ascii_only(self):
+ self.assertRaises(InvalidEmailAddressError,
+ self.registrar.register, self.mlist,
+ '\xa0@example.com')
+
+ def test_domain_required(self):
+ self.assertRaises(InvalidEmailAddressError,
+ self.registrar.register, self.mlist,
+ 'noatsign')
+
+ def test_full_domain_required(self):
+ self.assertRaises(InvalidEmailAddressError,
+ self.registrar.register, self.mlist,
+ 'nodom@ain')
+
+
+
+class TestRegistration(unittest.TestCase):
+ """Test registration."""
+
+ layer = ConfigLayer
+
+ def setUp(self):
+ self.registrar = getUtility(IRegistrar)
+ self.mlist = create_list('alpha@example.com')
+
+ def test_confirmation_event_received(self):
+ # Registering an email address generates an event.
+ def capture_event(event):
+ self.assertIsInstance(event, ConfirmationNeededEvent)
+ with event_subscribers(capture_event):
+ self.registrar.register(self.mlist, 'anne@example.com')
+
+ def test_event_mlist(self):
+ # The event has a reference to the mailing list being subscribed to.
+ def capture_event(event):
+ self.assertIs(event.mlist, self.mlist)
+ with event_subscribers(capture_event):
+ self.registrar.register(self.mlist, 'anne@example.com')
+
+ def test_event_pendable(self):
+ # The event has an IPendable which contains additional information.
+ def capture_event(event):
+ pendable = event.pendable
+ self.assertEqual(pendable['type'], 'registration')
+ self.assertEqual(pendable['email'], 'anne@example.com')
+ # The key is present, but the value is None.
+ self.assertIsNone(pendable['display_name'])
+ # The default is regular delivery.
+ self.assertEqual(pendable['delivery_mode'], 'regular')
+ self.assertEqual(pendable['list_id'], 'alpha.example.com')
+ with event_subscribers(capture_event):
+ self.registrar.register(self.mlist, 'anne@example.com')
+
+ def test_token(self):
+ # Registering the email address returns a token, and this token links
+ # back to the pendable.
+ captured_events = []
+ def capture_event(event):
+ captured_events.append(event)
+ with event_subscribers(capture_event):
+ token = self.registrar.register(self.mlist, 'anne@example.com')
+ self.assertEqual(len(captured_events), 1)
+ event = captured_events[0]
+ self.assertEqual(event.token, token)
+ pending = getUtility(IPendings).confirm(token)
+ self.assertEqual(pending, event.pendable)
diff --git a/src/mailman/app/tests/test_subscriptions.py b/src/mailman/app/tests/test_subscriptions.py
index 6d269ffac..e5aad18bc 100644
--- a/src/mailman/app/tests/test_subscriptions.py
+++ b/src/mailman/app/tests/test_subscriptions.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2011-2013 by the Free Software Foundation, Inc.
+# Copyright (C) 2011-2014 by the Free Software Foundation, Inc.
#
# This file is part of GNU Mailman.
#
diff --git a/src/mailman/app/tests/test_templates.py b/src/mailman/app/tests/test_templates.py
index 59c9a05df..afde68647 100644
--- a/src/mailman/app/tests/test_templates.py
+++ b/src/mailman/app/tests/test_templates.py
@@ -1,4 +1,4 @@
-# Copyright (C) 2012-2013 by the Free Software Foundation, Inc.
+# Copyright (C) 2012-2014 by the Free Software Foundation, Inc.
#
# This file is part of GNU Mailman.
#