summaryrefslogtreecommitdiff
path: root/src/mailman/model/tests
diff options
context:
space:
mode:
authorBarry Warsaw2015-03-26 16:47:09 -0400
committerBarry Warsaw2015-03-26 16:47:09 -0400
commit72630c5b467e14cce6f4d6480ae8640c69f92a3e (patch)
treed1d95e77bf106158e40a11de006680ce88cbe215 /src/mailman/model/tests
parentb2c2507402f0578e86bc37bac0711979270e8821 (diff)
parente16cd87fcbef9f7f1451378150404440dbdee0e8 (diff)
downloadmailman-72630c5b467e14cce6f4d6480ae8640c69f92a3e.tar.gz
mailman-72630c5b467e14cce6f4d6480ae8640c69f92a3e.tar.zst
mailman-72630c5b467e14cce6f4d6480ae8640c69f92a3e.zip
Merging in several refactorings, and a REST API change.
Backward Incompatible REST API Changes: * The JSON representation for subscription holds now no longer contains the `password` key. Also, the `address` key has been renamed to `email` for consistency with established terminology and other usage. Other Internal API Changes: * IUserManager has grown a `make_user()` method. Refactorings: * Most uses in the test suite of add_member() have been replaced with a new version of the subscribe() helper. This reduces the surface area of this ancient internal API. Eventually add_member() will have to go away or significantly change with the subscription policy workflow. * hold_subscription() as well as the remaining instances of add_member() now use a namedtuple in their arguments, to keep the signatures manageable.
Diffstat (limited to 'src/mailman/model/tests')
-rw-r--r--src/mailman/model/tests/test_usermanager.py42
1 files changed, 37 insertions, 5 deletions
diff --git a/src/mailman/model/tests/test_usermanager.py b/src/mailman/model/tests/test_usermanager.py
index 90fcdac0c..31f1a7275 100644
--- a/src/mailman/model/tests/test_usermanager.py
+++ b/src/mailman/model/tests/test_usermanager.py
@@ -33,18 +33,50 @@ from zope.component import getUtility
class TestUserManager(unittest.TestCase):
layer = ConfigLayer
+ def setUp(self):
+ self._usermanager = getUtility(IUserManager)
+
def test_create_user_with_existing_address(self):
# LP: #1418280. If a user is created when an email address is passed
# in, and that address already exists, the user object should not get
# created.
- manager = getUtility(IUserManager)
# Create the address we're going to try to duplicate.
- manager.create_address('anne@example.com')
+ self._usermanager.create_address('anne@example.com')
# There are no users.
- self.assertEqual(len(list(manager.users)), 0)
+ self.assertEqual(len(list(self._usermanager.users)), 0)
# Now create the user with an already existing address.
with self.assertRaises(ExistingAddressError) as cm:
- manager.create_user('anne@example.com')
+ self._usermanager.create_user('anne@example.com')
self.assertEqual(cm.exception.address, 'anne@example.com')
# There are still no users.
- self.assertEqual(len(list(manager.users)), 0)
+ self.assertEqual(len(list(self._usermanager.users)), 0)
+
+ def test_make_new_user(self):
+ # Neither the user nor address objects exist yet.
+ self.assertIsNone(self._usermanager.get_user('anne@example.com'))
+ self.assertIsNone(self._usermanager.get_address('anne@example.com'))
+ user = self._usermanager.make_user('anne@example.com', 'Anne Person')
+ self.assertIn('anne@example.com',
+ [address.email for address in user.addresses])
+ addresses = list(user.addresses)
+ self.assertEqual(len(addresses), 1)
+ address = addresses[0]
+ self.assertEqual(address.email, 'anne@example.com')
+ self.assertEqual(address.display_name, 'Anne Person')
+ self.assertEqual(address.user.display_name, 'Anne Person')
+ self.assertIs(address.user, user)
+
+ def test_make_linked_user(self):
+ # The address exists, but there is no linked user.
+ self.assertIsNone(self._usermanager.get_user('anne@example.com'))
+ address = self._usermanager.create_address('anne@example.com')
+ user = self._usermanager.make_user('anne@example.com', 'Anne Person')
+ self.assertIsNotNone(address.user)
+ self.assertIs(user, address.user)
+ self.assertIn(address, user.addresses)
+ self.assertEqual(user.display_name, 'Anne Person')
+
+ def test_make_user_exists(self):
+ user = self._usermanager.create_user('anne@example.com', 'Anne Person')
+ other_user = self._usermanager.make_user('anne@example.com')
+ self.assertIs(user, other_user)