summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/mailman/app/membership.py2
-rw-r--r--src/mailman/app/tests/__init__.py0
-rw-r--r--src/mailman/app/tests/test_membership.py76
-rw-r--r--src/mailman/docs/NEWS.txt1
-rw-r--r--src/mailman/testing/helpers.py30
-rw-r--r--src/mailman/testing/layers.py17
6 files changed, 110 insertions, 16 deletions
diff --git a/src/mailman/app/membership.py b/src/mailman/app/membership.py
index e8564bc60..32ba1ff42 100644
--- a/src/mailman/app/membership.py
+++ b/src/mailman/app/membership.py
@@ -104,7 +104,7 @@ def add_member(mlist, email, realname, password, delivery_mode, language):
else:
# The user exists and is linked to the address.
for address in user.addresses:
- if address.email == address:
+ if address.email == email:
break
else:
raise AssertionError(
diff --git a/src/mailman/app/tests/__init__.py b/src/mailman/app/tests/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/src/mailman/app/tests/__init__.py
diff --git a/src/mailman/app/tests/test_membership.py b/src/mailman/app/tests/test_membership.py
new file mode 100644
index 000000000..dc8009f65
--- /dev/null
+++ b/src/mailman/app/tests/test_membership.py
@@ -0,0 +1,76 @@
+# 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/>.
+
+"""Tests of application level membership functions."""
+
+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.app.membership import add_member
+from mailman.core.constants import system_preferences
+from mailman.interfaces.member import DeliveryMode
+from mailman.interfaces.usermanager import IUserManager
+from mailman.testing.helpers import reset_the_world
+from mailman.testing.layers import ConfigLayer
+
+
+
+class AddMemberTest(unittest.TestCase):
+ layer = ConfigLayer
+
+ def setUp(self):
+ self._mlist = create_list('test@example.com')
+
+ def tearDown(self):
+ reset_the_world()
+
+ def test_add_member_new_user(self):
+ # Test subscribing a user to a mailing list when the email address has
+ # not yet been associated with a user.
+ member = add_member(self._mlist, 'aperson@example.com',
+ 'Anne Person', '123', DeliveryMode.regular,
+ system_preferences.preferred_language)
+ self.assertEqual(member.address.email, 'aperson@example.com')
+ self.assertEqual(member.mailing_list, 'test@example.com')
+
+ def test_add_member_existing_user(self):
+ # Test subscribing a user to a mailing list when the email address has
+ # already been associated with a user.
+ user_manager = getUtility(IUserManager)
+ user_manager.create_user('aperson@example.com', 'Anne Person')
+ member = add_member(self._mlist, 'aperson@example.com',
+ 'Anne Person', '123', DeliveryMode.regular,
+ system_preferences.preferred_language)
+ self.assertEqual(member.address.email, 'aperson@example.com')
+ self.assertEqual(member.mailing_list, 'test@example.com')
+
+
+
+def test_suite():
+ suite = unittest.TestSuite()
+ suite.addTest(unittest.makeSuite(AddMemberTest))
+ return suite
diff --git a/src/mailman/docs/NEWS.txt b/src/mailman/docs/NEWS.txt
index ed91fb7aa..f86e805f4 100644
--- a/src/mailman/docs/NEWS.txt
+++ b/src/mailman/docs/NEWS.txt
@@ -60,6 +60,7 @@ Build
Bugs fixed
----------
* Typo in scan_message(). (LP: #645897)
+ * Typo in add_member(). (LP: #710182) (Florian Fuchs)
* Clean up many pyflakes problems.
diff --git a/src/mailman/testing/helpers.py b/src/mailman/testing/helpers.py
index fd2b9ffb3..2ba778813 100644
--- a/src/mailman/testing/helpers.py
+++ b/src/mailman/testing/helpers.py
@@ -26,6 +26,7 @@ __all__ = [
'get_lmtp_client',
'get_queue_messages',
'make_testable_runner',
+ 'reset_the_world',
'subscribe',
'wait_for_webservice',
]
@@ -47,6 +48,7 @@ from zope.component import getUtility
from mailman.bin.master import Loop as Master
from mailman.config import config
from mailman.interfaces.member import MemberRole
+from mailman.interfaces.messages import IMessageStore
from mailman.interfaces.usermanager import IUserManager
from mailman.utilities.mailbox import Mailbox
@@ -277,3 +279,31 @@ def subscribe(mlist, first_name, role=MemberRole.member):
preferred_address = list(person.addresses)[0]
preferred_address.subscribe(mlist, role)
config.db.commit()
+
+
+
+def reset_the_world():
+ """Reset everything:
+
+ * Clear out the database
+ * Remove all residual queue files
+ * Clear the message store
+ * Reset the global style manager
+
+ This should be as thorough a reset of the system as necessary to keep
+ tests isolated.
+ """
+ # Reset the database between tests.
+ config.db._reset()
+ # Remove all residual queue files.
+ for dirpath, dirnames, filenames in os.walk(config.QUEUE_DIR):
+ for filename in filenames:
+ os.remove(os.path.join(dirpath, filename))
+ # Clear out messages in the message store.
+ message_store = getUtility(IMessageStore)
+ for message in message_store.messages:
+ message_store.delete_message(message['message-id'])
+ config.db.commit()
+ # Reset the global style manager.
+ config.style_manager.populate()
+
diff --git a/src/mailman/testing/layers.py b/src/mailman/testing/layers.py
index 319248ebb..353dd9edd 100644
--- a/src/mailman/testing/layers.py
+++ b/src/mailman/testing/layers.py
@@ -46,8 +46,7 @@ from mailman.core import initialize
from mailman.core.initialize import INHIBIT_CONFIG_FILE
from mailman.core.logging import get_handler
from mailman.interfaces.domain import IDomainManager
-from mailman.interfaces.messages import IMessageStore
-from mailman.testing.helpers import TestableMaster
+from mailman.testing.helpers import TestableMaster, reset_the_world
from mailman.testing.mta import ConnectionCountingController
from mailman.utilities.datetime import factory
from mailman.utilities.string import expand
@@ -179,19 +178,7 @@ class ConfigLayer(MockAndMonkeyLayer):
@classmethod
def testTearDown(cls):
- # Reset the database between tests.
- config.db._reset()
- # Remove all residual queue files.
- for dirpath, dirnames, filenames in os.walk(config.QUEUE_DIR):
- for filename in filenames:
- os.remove(os.path.join(dirpath, filename))
- # Clear out messages in the message store.
- message_store = getUtility(IMessageStore)
- for message in message_store.messages:
- message_store.delete_message(message['message-id'])
- config.db.commit()
- # Reset the global style manager.
- config.style_manager.populate()
+ reset_the_world()
# Flag to indicate that loggers should propagate to the console.
stderr = False