diff --git a/src/postorius/tests/mailman_api_tests/test_domain_delete.py b/src/postorius/tests/mailman_api_tests/test_domain_delete.py index 19e2fe9..3f35f75 100644 --- a/src/postorius/tests/mailman_api_tests/test_domain_delete.py +++ b/src/postorius/tests/mailman_api_tests/test_domain_delete.py @@ -17,6 +17,7 @@ from __future__ import absolute_import, print_function, unicode_literals +from allauth.account.models import EmailAddress from django.core.urlresolvers import reverse from django.contrib.auth.models import User @@ -39,6 +40,9 @@ 'testowner', 'owner@example.com', 'testpass') self.moderator = User.objects.create_user( 'testmoderator', 'moderator@example.com', 'testpass') + for user in (self.user, self.superuser, self.owner, self.moderator): + EmailAddress.objects.create( + user=user, email=user.email, verified=True) self.foo_list.add_owner('owner@example.com') self.foo_list.add_moderator('moderator@example.com') self.url = reverse('domain_delete', args=['example.com']) diff --git a/src/postorius/tests/mailman_api_tests/test_domain_index.py b/src/postorius/tests/mailman_api_tests/test_domain_index.py index 0f41c54..0f79193 100644 --- a/src/postorius/tests/mailman_api_tests/test_domain_index.py +++ b/src/postorius/tests/mailman_api_tests/test_domain_index.py @@ -17,6 +17,7 @@ from __future__ import absolute_import, print_function, unicode_literals +from allauth.account.models import EmailAddress from django.core.urlresolvers import reverse from django.contrib.auth.models import User try: @@ -46,6 +47,9 @@ 'testowner', 'owner@example.com', 'testpass') self.moderator = User.objects.create_user( 'testmoderator', 'moderator@example.com', 'testpass') + for user in (self.user, self.superuser, self.owner, self.moderator): + EmailAddress.objects.create( + user=user, email=user.email, verified=True) self.foo_list.add_owner('owner@example.com') self.foo_list.add_moderator('moderator@example.com') diff --git a/src/postorius/tests/mailman_api_tests/test_domain_new.py b/src/postorius/tests/mailman_api_tests/test_domain_new.py index ea92ae1..2d7dfaf 100644 --- a/src/postorius/tests/mailman_api_tests/test_domain_new.py +++ b/src/postorius/tests/mailman_api_tests/test_domain_new.py @@ -17,6 +17,7 @@ from __future__ import absolute_import, print_function, unicode_literals +from allauth.account.models import EmailAddress from django.contrib.auth.models import User from django.core.urlresolvers import reverse @@ -31,6 +32,9 @@ self.user = User.objects.create_user('user', 'user@example.com', 'pwd') self.superuser = User.objects.create_superuser('su', 'su@example.com', 'pwd') + for user in (self.user, self.superuser): + EmailAddress.objects.create( + user=user, email=user.email, verified=True) def test_permission_denied(self): self.client.login(username='user', password='pwd') diff --git a/src/postorius/tests/mailman_api_tests/test_list_bans.py b/src/postorius/tests/mailman_api_tests/test_list_bans.py index fdf2af1..fdebb9b 100644 --- a/src/postorius/tests/mailman_api_tests/test_list_bans.py +++ b/src/postorius/tests/mailman_api_tests/test_list_bans.py @@ -19,6 +19,7 @@ from __future__ import absolute_import, print_function, unicode_literals +from allauth.account.models import EmailAddress from django.contrib.auth.models import User from django.core.urlresolvers import reverse @@ -36,6 +37,9 @@ 'test_user', 'test_user@example.com', 'pwd') self.test_superuser = User.objects.create_superuser( 'test_superuser', 'test_superuser@example.com', 'pwd') + for user in (self.test_user, self.test_superuser): + EmailAddress.objects.create( + user=user, email=user.email, verified=True) self.client.login(username="test_superuser", password='pwd') self.url = reverse('list_bans', args=['test_list.example.com']) diff --git a/src/postorius/tests/mailman_api_tests/test_list_header_matches.py b/src/postorius/tests/mailman_api_tests/test_list_header_matches.py index f652181..8f9a524 100644 --- a/src/postorius/tests/mailman_api_tests/test_list_header_matches.py +++ b/src/postorius/tests/mailman_api_tests/test_list_header_matches.py @@ -19,6 +19,7 @@ from __future__ import absolute_import, print_function, unicode_literals +from allauth.account.models import EmailAddress from django.contrib.auth.models import User from django.core.urlresolvers import reverse @@ -42,6 +43,9 @@ 'testowner', 'owner@example.com', 'testpass') self.moderator = User.objects.create_user( 'testmoderator', 'moderator@example.com', 'testpass') + for user in (self.user, self.superuser, self.owner, self.moderator): + EmailAddress.objects.create( + user=user, email=user.email, verified=True) self.mlist.add_owner('owner@example.com') self.mlist.add_moderator('moderator@example.com') diff --git a/src/postorius/tests/mailman_api_tests/test_list_member_options.py b/src/postorius/tests/mailman_api_tests/test_list_member_options.py index 0470c6a..8e60af6 100644 --- a/src/postorius/tests/mailman_api_tests/test_list_member_options.py +++ b/src/postorius/tests/mailman_api_tests/test_list_member_options.py @@ -14,8 +14,10 @@ # # You should have received a copy of the GNU General Public License along with # Postorius. If not, see . + from __future__ import absolute_import, print_function, unicode_literals +from allauth.account.models import EmailAddress from django.conf import settings from django.contrib.auth.models import User from django.core.urlresolvers import reverse @@ -44,6 +46,9 @@ 'testowner', 'owner@example.com', 'testpass') self.moderator = User.objects.create_user( 'testmoderator', 'moderator@example.com', 'testpass') + for user in (self.user, self.superuser, self.owner, self.moderator): + EmailAddress.objects.create( + user=user, email=user.email, verified=True) self.foo_list.add_owner('owner@example.com') self.foo_list.add_moderator('moderator@example.com') self.mm_user = get_mailman_client().create_user('test@example.com', '') diff --git a/src/postorius/tests/mailman_api_tests/test_list_members.py b/src/postorius/tests/mailman_api_tests/test_list_members.py index 229a046..9bdad7f 100644 --- a/src/postorius/tests/mailman_api_tests/test_list_members.py +++ b/src/postorius/tests/mailman_api_tests/test_list_members.py @@ -17,6 +17,7 @@ from __future__ import absolute_import, print_function, unicode_literals +from allauth.account.models import EmailAddress from django.contrib.auth.models import User from django.core.urlresolvers import reverse @@ -41,6 +42,9 @@ 'testowner', 'owner@example.com', 'testpass') self.moderator = User.objects.create_user( 'testmoderator', 'moderator@example.com', 'testpass') + for user in (self.user, self.superuser, self.owner, self.moderator): + EmailAddress.objects.create( + user=user, email=user.email, verified=True) self.foo_list.add_owner('owner@example.com') self.foo_list.add_moderator('moderator@example.com') @@ -86,6 +90,8 @@ self.foo_list = self.domain.create_list('foo') self.su = User.objects.create_superuser( 'su', 'su@example.com', 'pwd') + EmailAddress.objects.create( + user=self.su, email=self.su.email, verified=True) self.client.login(username='su', password='pwd') self.mm_client.get_list('foo@example.com').add_owner('su@example.com') @@ -158,6 +164,8 @@ self.foo_list = self.domain.create_list('foo') self.su = User.objects.create_superuser( 'su', 'su@example.com', 'pwd') + EmailAddress.objects.create( + user=self.su, email=self.su.email, verified=True) # login and post new moderator data to url self.client.login(username='su', password='pwd') url = reverse('list_members', args=('foo@example.com', 'moderator',)) @@ -183,6 +191,8 @@ self.foo_list = self.domain.create_list('foo') self.superuser = User.objects.create_superuser( 'testsu', 'su@example.com', 'testpass') + EmailAddress.objects.create( + user=self.superuser, email=self.superuser.email, verified=True) def tearDown(self): self.foo_list.delete() diff --git a/src/postorius/tests/mailman_api_tests/test_list_new.py b/src/postorius/tests/mailman_api_tests/test_list_new.py index 6b558c6..1ed0fa3 100644 --- a/src/postorius/tests/mailman_api_tests/test_list_new.py +++ b/src/postorius/tests/mailman_api_tests/test_list_new.py @@ -17,6 +17,7 @@ from __future__ import absolute_import, print_function, unicode_literals +from allauth.account.models import EmailAddress from django.contrib.auth.models import User from django.core.urlresolvers import reverse @@ -31,6 +32,9 @@ self.user = User.objects.create_user('user', 'user@example.com', 'pwd') self.superuser = User.objects.create_superuser('su', 'su@example.com', 'pwd') + for user in (self.user, self.superuser): + EmailAddress.objects.create( + user=user, email=user.email, verified=True) self.domain = self.mm_client.create_domain('example.com') def test_permission_denied(self): diff --git a/src/postorius/tests/mailman_api_tests/test_list_settings.py b/src/postorius/tests/mailman_api_tests/test_list_settings.py index ba10b5b..0e1e35d 100644 --- a/src/postorius/tests/mailman_api_tests/test_list_settings.py +++ b/src/postorius/tests/mailman_api_tests/test_list_settings.py @@ -19,6 +19,7 @@ from __future__ import absolute_import, print_function, unicode_literals +from allauth.account.models import EmailAddress from django.contrib.auth.models import User from django.core.urlresolvers import reverse @@ -44,6 +45,9 @@ 'testowner', 'owner@example.com', 'testpass') self.moderator = User.objects.create_user( 'testmoderator', 'moderator@example.com', 'testpass') + for user in (self.user, self.superuser, self.owner, self.moderator): + EmailAddress.objects.create( + user=user, email=user.email, verified=True) self.foo_list.add_owner('owner@example.com') self.foo_list.add_moderator('moderator@example.com') diff --git a/src/postorius/tests/mailman_api_tests/test_list_summary.py b/src/postorius/tests/mailman_api_tests/test_list_summary.py index c5edeb8..d72d451 100644 --- a/src/postorius/tests/mailman_api_tests/test_list_summary.py +++ b/src/postorius/tests/mailman_api_tests/test_list_summary.py @@ -17,6 +17,7 @@ from __future__ import absolute_import, print_function, unicode_literals +from allauth.account.models import EmailAddress from django.contrib.auth.models import User from django.core.urlresolvers import reverse @@ -34,7 +35,10 @@ super(ListSummaryPageTest, self).setUp() self.domain = self.mm_client.create_domain('example.com') self.foo_list = self.domain.create_list('foo') - User.objects.create_user('testuser', 'test@example.com', 'testpass') + self.user = User.objects.create_user( + 'testuser', 'test@example.com', 'testpass') + EmailAddress.objects.create( + user=self.user, email=self.user.email, verified=True) def test_list_summary_logged_out(self): # Response must contain list obj but not the form. @@ -57,6 +61,8 @@ def test_list_summary_shows_all_addresses(self): mlist = self.mm_client.get_list('foo@example.com') mlist.subscribe('test@example.com') + EmailAddress.objects.create( + user=self.user, email='anotheremail@example.com', verified=True) user = self.mm_client.get_user('test@example.com') address = user.add_address('anotheremail@example.com') address.verify() @@ -100,6 +106,8 @@ def test_list_summary_is_admin_secondary_owner(self): # Response must contain the administration menu + EmailAddress.objects.create( + user=self.user, email='anotheremail@example.com', verified=True) user = self.mm_client.create_user('test@example.com', None) address = user.add_address('anotheremail@example.com') address.verify() @@ -112,6 +120,8 @@ def test_list_summary_is_admin_secondary_moderator(self): # Response must contain the administration menu + EmailAddress.objects.create( + user=self.user, email='anotheremail@example.com', verified=True) user = self.mm_client.create_user('test@example.com', None) address = user.add_address('anotheremail@example.com') address.verify() @@ -146,8 +156,10 @@ self.assertContains(response, 'List metrics') def test_list_metrics_displayed_to_superuser(self): - User.objects.create_superuser('testadminuser', 'testadmin@example.com', - 'testpass') + user = User.objects.create_superuser( + 'testadminuser', 'testadmin@example.com', 'testpass') + EmailAddress.objects.create( + user=user, email=user.email, verified=True) self.assertTrue(self.client.login(username='testadminuser', password='testpass')) response = self.client.get(reverse('list_summary', diff --git a/src/postorius/tests/mailman_api_tests/test_models.py b/src/postorius/tests/mailman_api_tests/test_models.py index 0dfad43..79fa23f 100644 --- a/src/postorius/tests/mailman_api_tests/test_models.py +++ b/src/postorius/tests/mailman_api_tests/test_models.py @@ -17,6 +17,7 @@ from __future__ import absolute_import, print_function, unicode_literals +from allauth.account.models import EmailAddress from django.contrib.auth.models import User try: from urllib2 import HTTPError @@ -36,14 +37,18 @@ def test_mailman_user_not_created_when_flag_is_off(self): with self.settings(AUTOCREATE_MAILMAN_USER=False): - User.objects.create_user('testuser', 'test@example.com', - 'testpass') + user = User.objects.create_user( + 'testuser', 'test@example.com', 'testpass') + EmailAddress.objects.create( + user=user, email=user.email, verified=True) with self.assertRaises(HTTPError): self.mm_client.get_user('test@example.com') def test_mailman_user_created_when_flag_is_on(self): with self.settings(AUTOCREATE_MAILMAN_USER=True): - User.objects.create_user('testuser', 'test@example.com', - 'testpass') - user = self.mm_client.get_user('test@example.com') - self.assertEqual(str(user.addresses[0]), 'test@example.com') + user = User.objects.create_user( + 'testuser', 'test@example.com', 'testpass') + EmailAddress.objects.create( + user=user, email=user.email, verified=True) + mm_user = self.mm_client.get_user('test@example.com') + self.assertEqual(str(mm_user.addresses[0]), 'test@example.com') diff --git a/src/postorius/tests/mailman_api_tests/test_subscriptions.py b/src/postorius/tests/mailman_api_tests/test_subscriptions.py index a4019d3..ea87ba6 100644 --- a/src/postorius/tests/mailman_api_tests/test_subscriptions.py +++ b/src/postorius/tests/mailman_api_tests/test_subscriptions.py @@ -17,6 +17,7 @@ from __future__ import absolute_import, print_function, unicode_literals +from allauth.account.models import EmailAddress from django.contrib.auth.models import User from django.core.urlresolvers import reverse @@ -42,6 +43,10 @@ # Create django user. self.user = User.objects.create_user( 'testuser', 'test@example.com', 'pwd') + EmailAddress.objects.create( + user=self.user, email=self.user.email, verified=True) + EmailAddress.objects.create( + user=self.user, email='fritz@example.org', verified=True) # Create Mailman user self.mm_user = self.mm_client.create_user('test@example.com', '') self.mm_user.add_address('fritz@example.org') @@ -153,7 +158,10 @@ self.assertIn('Already subscribed', message) def test_subscribe_with_name(self): - User.objects.create_user('testowner', 'owner@example.com', 'pwd') + owner = User.objects.create_user( + 'testowner', 'owner@example.com', 'pwd') + EmailAddress.objects.create( + user=owner, email=owner.email, verified=True) self.open_list.add_owner('owner@example.com') self.client.login(username='testowner', password='pwd') email_list = """First Person \n diff --git a/src/postorius/tests/mailman_api_tests/test_user.py b/src/postorius/tests/mailman_api_tests/test_user.py index 1fbe8da..b86c086 100644 --- a/src/postorius/tests/mailman_api_tests/test_user.py +++ b/src/postorius/tests/mailman_api_tests/test_user.py @@ -17,6 +17,7 @@ from __future__ import absolute_import, print_function, unicode_literals +from allauth.account.models import EmailAddress from django.contrib.auth.models import User from django.core.urlresolvers import reverse from django.test.utils import override_settings @@ -38,6 +39,8 @@ self.foo_list = self.domain.create_list('foo') self.user = User.objects.create_user( 'user', 'user@example.com', 'testpass') + EmailAddress.objects.create( + user=self.user, email=self.user.email, verified=True) self.mm_user = MailmanUser.objects.create_from_django(self.user) def test_address_preferences_not_logged_in(self): @@ -112,6 +115,8 @@ # cause views to crash. user = User.objects.create_user( 'old-user', 'old-user@example.com', 'testpass') + EmailAddress.objects.create( + user=user, email=user.email, verified=True) self.client.login(username='old-user', password='testpass') self.assertRaises(Mailman404Error, MailmanUser.objects.get, address=user.email) diff --git a/src/postorius/tests/test_auth_decorators.py b/src/postorius/tests/test_auth_decorators.py index 44a3ff3..1d4e925 100644 --- a/src/postorius/tests/test_auth_decorators.py +++ b/src/postorius/tests/test_auth_decorators.py @@ -15,6 +15,7 @@ # You should have received a copy of the GNU General Public License along with # Postorius. If not, see . +from allauth.account.models import EmailAddress from django.contrib.auth.models import AnonymousUser, User from django.core.exceptions import PermissionDenied from django.test.client import RequestFactory @@ -43,6 +44,14 @@ return True +def create_user(): + user = User.objects.create_user( + 'les c', 'les@primus.org', 'pwd') + EmailAddress.objects.create( + user=user, email=user.email, verified=True) + return user + + class ListOwnerRequiredTest(TestCase): """Tests the list_owner_required auth decorator.""" @@ -74,6 +83,8 @@ '/lists/foolist.example.org/settings/') request.user = User.objects.create_superuser( 'su1', 'su@sodo.org', 'pwd') + EmailAddress.objects.create( + user=request.user, email=request.user.email, verified=True) return_value = dummy_function( request, list_id='foolist.example.org') self.assertEqual(return_value, True) @@ -87,8 +98,7 @@ # prepare request request = self.request_factory.get( '/lists/foolist.example.org/settings/') - request.user = User.objects.create_user( - 'les c', 'les@primus.org', 'pwd') + request.user = create_user() self.assertRaises(PermissionDenied, dummy_function, request, list_id='foolist.example.org') @@ -101,8 +111,7 @@ # prepare request request = self.request_factory.get( '/lists/foolist.example.org/settings/') - request.user = User.objects.create_user( - 'les cl', 'les@primus.org', 'pwd') + request.user = create_user() return_value = dummy_function( request, list_id='foolist.example.org') self.assertEqual(return_value, True) @@ -139,6 +148,8 @@ '/lists/foolist.example.org/settings/') request.user = User.objects.create_superuser( 'su2', 'su@sodo.org', 'pwd') + EmailAddress.objects.create( + user=request.user, email=request.user.email, verified=True) return_value = dummy_function_mod_req( request, list_id='foolist.example.org') self.assertEqual(return_value, True) @@ -152,8 +163,7 @@ # prepare request request = self.request_factory.get( '/lists/foolist.example.org/settings/') - request.user = User.objects.create_user( - 'les cl2', 'les@primus.org', 'pwd') + request.user = create_user() self.assertRaises(PermissionDenied, dummy_function_mod_req, request, list_id='foolist.example.org') @@ -166,8 +176,7 @@ # prepare request request = self.request_factory.get( '/lists/foolist.example.org/settings/') - request.user = User.objects.create_user( - 'les cl3', 'les@primus.org', 'pwd') + request.user = create_user() return_value = dummy_function_mod_req( request, list_id='foolist.example.org') self.assertEqual(return_value, True) @@ -181,8 +190,7 @@ # prepare request request = self.request_factory.get( '/lists/foolist.example.org/settings/') - request.user = User.objects.create_user( - 'les cl4', 'les@primus.org', 'pwd') + request.user = create_user() return_value = dummy_function_mod_req( request, list_id='foolist.example.org') self.assertEqual(return_value, True) @@ -217,8 +225,7 @@ request = self.request_factory.get( '/lists/foolist.example.org/settings/') - request.user = User.objects.create_user( - 'new user', 'new@usersfactory.net', 'testing') + request.user = create_user() self.assertRaises(PermissionDenied, dummy_superuser_or_403, request) @patch.object(Client, 'get_list') @@ -228,6 +235,7 @@ request = self.request_factory.get( '/lists/foolist.example.org/settings/') - request.user = User.objects.create_superuser( - 'new su', 'new@su.net', 'testing') + request.user = create_user() + request.user.is_superuser = True + request.user.save() self.assertTrue(dummy_superuser_or_403(request)) diff --git a/src/postorius/tests/test_domain_view.py b/src/postorius/tests/test_domain_view.py index 8009925..b4d513f 100644 --- a/src/postorius/tests/test_domain_view.py +++ b/src/postorius/tests/test_domain_view.py @@ -14,6 +14,10 @@ # # You should have received a copy of the GNU General Public License along with # Postorius. If not, see . + +from __future__ import absolute_import, print_function, unicode_literals + +from allauth.account.models import EmailAddress from django.test import TestCase from django.core.urlresolvers import reverse from django.contrib.auth.models import User @@ -25,6 +29,8 @@ def setUp(self): self.user = User.objects.create_superuser('su', 'su@example.com', 'pass') + EmailAddress.objects.create( + user=self.user, email=self.user.email, verified=True) def tearDown(self): self.user.delete()