Merge ~pelpsi/launchpad:send-bug-notifications-opsees-list-index-out-of-range into launchpad:master

Proposed by Simone Pelosi
Status: Merged
Approved by: Simone Pelosi
Approved revision: ca69e01540ff79d9fa7a44d62b50a95a0180d4e5
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~pelpsi/launchpad:send-bug-notifications-opsees-list-index-out-of-range
Merge into: launchpad:master
Diff against target: 104 lines (+66/-5)
2 files modified
lib/lp/bugs/model/bugnotification.py (+10/-5)
lib/lp/bugs/scripts/tests/test_bugnotification.py (+56/-0)
Reviewer Review Type Date Requested Status
Ines Almeida Approve
Review via email: mp+445114@code.launchpad.net

Commit message

Fixed list index out of range

filters_by_person[x] set was replaced every iteration.
Now it's updated using the "update" set function.

To post a comment you must log in.
Revision history for this message
Ines Almeida (ines-almeida) wrote :

Makes sense to me!
Only a very minor comment

review: Approve
Revision history for this message
Simone Pelosi (pelpsi) wrote :

> Makes sense to me!
> Only a very minor comment

Thank you for your meticulous review Ines! I will remove unnecessary information.
We need datecreated information in the notification constructor because we want a non-expired notification.

Revision history for this message
Simone Pelosi (pelpsi) wrote :

Squashing all commits into one.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/bugs/model/bugnotification.py b/lib/lp/bugs/model/bugnotification.py
2index bb51a63..7078cda 100644
3--- a/lib/lp/bugs/model/bugnotification.py
4+++ b/lib/lp/bugs/model/bugnotification.py
5@@ -327,10 +327,12 @@ class BugNotificationSet:
6 ] = filter_description
7 filter_ids.append(filter_id)
8
9- filters_by_person[source_person_id] = {
10- (i, filter_id)
11- for i in source_person_id_map[source_person_id]["sources"]
12- }
13+ filters_by_person[source_person_id].update(
14+ {
15+ (i, filter_id)
16+ for i in source_person_id_map[source_person_id]["sources"]
17+ }
18+ )
19
20 # Remaining notifications have no filters
21 source_filter_ids = filters_by_person.keys()
22@@ -392,7 +394,10 @@ class BugNotificationSet:
23 for recipient_data in recipient_id_map.values():
24 # Getting filtered sources
25
26- if recipient_data["filters"]:
27+ if (
28+ recipient_data["filters"]
29+ and filters_by_person[recipient_data["principal"].id]
30+ ):
31 filter_descriptions = [
32 description
33 for description in recipient_data["filters"].values()
34diff --git a/lib/lp/bugs/scripts/tests/test_bugnotification.py b/lib/lp/bugs/scripts/tests/test_bugnotification.py
35index b9b0a0a..a863751 100644
36--- a/lib/lp/bugs/scripts/tests/test_bugnotification.py
37+++ b/lib/lp/bugs/scripts/tests/test_bugnotification.py
38@@ -54,6 +54,7 @@ from lp.bugs.scripts.bugnotification import (
39 notification_comment_batches,
40 process_deferred_notifications,
41 )
42+from lp.registry.enums import TeamMembershipPolicy
43 from lp.registry.interfaces.person import IPersonSet
44 from lp.registry.interfaces.product import IProductSet
45 from lp.services.config import config
46@@ -1572,3 +1573,58 @@ class TestSendBugNotifications(TestCaseWithFactory):
47 self.assertEqual(
48 "team-participant", messages[1]["X-Launchpad-Message-For"]
49 )
50+
51+ def test_team_subscription_with_multiple_filters(self):
52+
53+ team_owner = self.factory.makePerson(email="team-owner@canonical.com")
54+
55+ bug_watcher = self.factory.makePerson(
56+ name="bug-watcher-name", email="bug-watcher@canonical.com"
57+ )
58+
59+ team = self.factory.makeTeam(
60+ name="team-name",
61+ owner=team_owner,
62+ members=[bug_watcher, team_owner],
63+ membership_policy=TeamMembershipPolicy.RESTRICTED,
64+ )
65+
66+ bug = self.factory.makeBug(owner=team_owner)
67+
68+ subscription = bug.default_bugtask.target.addSubscription(
69+ team, team_owner
70+ )
71+
72+ message = getUtility(IMessageSet).fromText(
73+ "subject",
74+ "a comment.",
75+ team_owner,
76+ datecreated=self.ten_minutes_ago,
77+ )
78+ recipients = bug.getBugNotificationRecipients()
79+ notification = getUtility(IBugNotificationSet).addNotification(
80+ bug=bug,
81+ is_comment=True,
82+ message=message,
83+ recipients=recipients,
84+ activity=None,
85+ )
86+
87+ bug_filter = subscription.newBugFilter()
88+ BugNotificationFilter(
89+ bug_notification=notification,
90+ bug_subscription_filter=bug_filter,
91+ )
92+ BugSubscriptionFilterMute(
93+ person=bug_watcher,
94+ filter=bug_filter,
95+ )
96+ notification = self.notification_set.getNotificationsToSend()
97+
98+ pending_notification = get_email_notifications(notification)
99+
100+ _, _, messages = list(pending_notification)[0]
101+
102+ self.assertEqual(1, len(messages))
103+ self.assertEqual("bug-watcher@canonical.com", messages[0]["To"])
104+ self.assertEqual("team-name", messages[0]["X-Launchpad-Message-For"])

Subscribers

People subscribed via source and target branches

to status/vote changes: