← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] lp:~cjwatson/launchpad/testfix-team-mail into lp:launchpad

 

Colin Watson has proposed merging lp:~cjwatson/launchpad/testfix-team-mail into lp:launchpad.

Commit message:
Fix test regressions from team-mail changes.

Requested reviews:
  Colin Watson (cjwatson)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/testfix-team-mail/+merge/270561

Fix test regressions from team-mail changes.
-- 
Your team Launchpad code reviewers is subscribed to branch lp:launchpad.
=== modified file 'database/schema/security.cfg'
--- database/schema/security.cfg	2015-09-08 11:56:33 +0000
+++ database/schema/security.cfg	2015-09-09 16:54:47 +0000
@@ -1845,10 +1845,12 @@
 
 [mlist-import]
 public.emailaddress                     = SELECT, INSERT, UPDATE
+public.job                              = SELECT, INSERT
 public.mailinglist                      = SELECT, INSERT, UPDATE
 public.mailinglistsubscription          = SELECT, INSERT, UPDATE
 public.person                           = SELECT, INSERT, UPDATE
 public.personsettings                   = SELECT, INSERT
+public.persontransferjob                = SELECT, INSERT
 public.teammembership                   = SELECT, INSERT, UPDATE
 public.teamparticipation                = SELECT, INSERT, UPDATE
 type=user

=== modified file 'lib/lp/bugs/browser/tests/test_expose.py'
--- lib/lp/bugs/browser/tests/test_expose.py	2015-07-08 16:05:11 +0000
+++ lib/lp/bugs/browser/tests/test_expose.py	2015-09-09 16:54:47 +0000
@@ -1,4 +1,4 @@
-# Copyright 2011 Canonical Ltd.  This software is licensed under the
+# Copyright 2011-2015 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Tests for helpers that expose data about a user to on-page JavaScript."""
@@ -183,6 +183,7 @@
         context = self.factory.makeProduct(owner=self.user)
         self._setup_teams(self.user)
 
+        IStore(Person).flush()
         IStore(Person).invalidate()
         clear_cache()
         with StormStatementRecorder() as recorder:
@@ -201,6 +202,7 @@
             pt.addMember(
                 self.user, pt.teamowner, status=TeamMembershipStatus.ADMIN)
 
+        IStore(Person).flush()
         IStore(Person).invalidate()
         clear_cache()
         del IJSONRequestCache(self.request).objects['administratedTeams']

=== modified file 'lib/lp/registry/tests/test_mlists.py'
--- lib/lp/registry/tests/test_mlists.py	2012-09-28 06:15:58 +0000
+++ lib/lp/registry/tests/test_mlists.py	2015-09-09 16:54:47 +0000
@@ -1,4 +1,4 @@
-# Copyright 2009-2011 Canonical Ltd.  This software is licensed under the
+# Copyright 2009-2015 Canonical Ltd.  This software is licensed under the
 # GNU Affero General Public License version 3 (see the file LICENSE).
 
 """Test mailing list stuff."""
@@ -24,8 +24,12 @@
     TeamMembershipPolicy,
     )
 from lp.registry.interfaces.mailinglist import IMailingListSet
+from lp.registry.interfaces.persontransferjob import (
+    ITeamJoinNotificationJobSource,
+    )
 from lp.registry.scripts.mlistimport import Importer
 from lp.services.identity.interfaces.emailaddress import EmailAddressStatus
+from lp.services.job.runner import JobRunner
 from lp.services.log.logger import BufferLogger
 from lp.testing import (
     login,
@@ -38,6 +42,8 @@
     DatabaseFunctionalLayer,
     LayerProcessController,
     )
+from lp.testing.mail_helpers import pop_notifications
+from lp.testing.pages import permissive_security_policy
 
 
 factory = LaunchpadObjectFactory()
@@ -386,7 +392,7 @@
         # be committed, otherwise the script won't see the changes.
         transaction.commit()
         # Make sure the mailbox is empty.
-        LayerProcessController.smtp_controller.reset()
+        pop_notifications()
 
     def makeProcess(self, *extra_args):
         args = ['scripts/mlist-import.py', '--filename', self.filename]
@@ -397,6 +403,11 @@
                      env=dict(LPCONFIG=BaseLayer.appserver_config_name,
                               PATH=os.environ['PATH']))
 
+    def runMailJobs(self):
+        with permissive_security_policy('person-transfer-job'):
+            JobRunner.fromReady(
+                getUtility(ITeamJoinNotificationJobSource)).runAll()
+
     def test_import(self):
         # Test that a simple invocation of the script works.
         # Use various combinations of formats supported by parseaddr().
@@ -432,9 +443,10 @@
         process = self.makeProcess()
         stdout, stderr = process.communicate()
         self.assertEqual(process.returncode, 0, stdout)
-        # There should be no messages sitting in the smtp controller, because
-        # all notifications were suppressed.
-        messages = list(LayerProcessController.smtp_controller)
+        self.runMailJobs()
+        # There should be no messages sitting in the queue, because all
+        # notifications were suppressed.
+        messages = pop_notifications()
         self.assertEqual(len(messages), 0)
 
     def test_notifications(self):
@@ -457,14 +469,17 @@
         process = self.makeProcess('--notifications')
         stdout, stderr = process.communicate()
         self.assertEqual(process.returncode, 0, stdout)
-        # There should be five messages sitting in the smtp controller, one
-        # for each added new member, all sent to the team owner.
-        messages = list(LayerProcessController.smtp_controller)
+        self.runMailJobs()
+        # There should be five messages sitting in the queue, one for each
+        # added new member, all sent to the team owner.
+        messages = pop_notifications()
         self.assertEqual(len(messages), 5)
         # The messages are all being sent to the team owner.
         recipients = set(message['to'] for message in messages)
         self.assertEqual(len(recipients), 1)
-        self.assertEqual(recipients.pop(), 'teamowner.person@xxxxxxxxxxx')
+        self.assertEqual(
+            recipients.pop(),
+            'Teamowner Person <teamowner.person@xxxxxxxxxxx>')
         # The Subjects of all the messages indicate who was joined as a member
         # of the team.
         subjects = sorted(message['subject'] for message in messages)


References