From 4731ee37836df748285e3e86f74a7a58cc73d2f5 Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Thu, 26 Mar 2015 16:06:23 -0400 Subject: Extended test helper subscribe() which takes an optional email address and returns the newly created member. --- src/mailman/testing/helpers.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) (limited to 'src/mailman/testing/helpers.py') diff --git a/src/mailman/testing/helpers.py b/src/mailman/testing/helpers.py index a869c8d55..8fa4fbd2f 100644 --- a/src/mailman/testing/helpers.py +++ b/src/mailman/testing/helpers.py @@ -435,10 +435,14 @@ class chdir: -def subscribe(mlist, first_name, role=MemberRole.member): - """Helper for subscribing a sample person to a mailing list.""" +def subscribe(mlist, first_name, role=MemberRole.member, email=None): + """Helper for subscribing a sample person to a mailing list. + + Returns the newly created member object. + """ user_manager = getUtility(IUserManager) - email = '{0}person@example.com'.format(first_name[0].lower()) + email = ('{0}person@example.com'.format(first_name[0].lower()) + if email is None else email) full_name = '{0} Person'.format(first_name) with transaction(): person = user_manager.get_user(email) @@ -446,13 +450,14 @@ def subscribe(mlist, first_name, role=MemberRole.member): address = user_manager.get_address(email) if address is None: person = user_manager.create_user(email, full_name) - preferred_address = list(person.addresses)[0] - mlist.subscribe(preferred_address, role) + subscription_address = list(person.addresses)[0] else: - mlist.subscribe(address, role) + subscription_address = address else: - preferred_address = list(person.addresses)[0] - mlist.subscribe(preferred_address, role) + subscription_address = list(person.addresses)[0] + mlist.subscribe(subscription_address, role) + roster = mlist.get_roster(role) + return roster.get_member(email) -- cgit v1.2.3-70-g09d2