Merge lp:~gmb/launchpad/prevent-bnl-nothing-oopses-bug-721400 into lp:launchpad

Proposed by Graham Binns
Status: Merged
Merged at revision: 12527
Proposed branch: lp:~gmb/launchpad/prevent-bnl-nothing-oopses-bug-721400
Merge into: lp:launchpad
Diff against target: 92 lines (+36/-3)
3 files modified
lib/lp/bugs/browser/bugsubscription.py (+5/-3)
lib/lp/bugs/browser/tests/test_bugsubscription_views.py (+26/-0)
lib/lp/bugs/enum.py (+5/-0)
To merge this branch: bzr merge lp:~gmb/launchpad/prevent-bnl-nothing-oopses-bug-721400
Reviewer Review Type Date Requested Status
Gavin Panella (community) Approve
Review via email: mp+52036@code.launchpad.net

Commit message

[r=allenap][ui=none] [r=allenap][bug=721400] The BugTask:+subscribe page will no longer OOPS if the user already has a subscription with a bug_notification_level of NOTHING.

Description of the change

This branch fixes bug 721400, wherein the BugTask:+subscribe page would
OOPS if the user had an existing subscription with a
bug_notification_level of NOTHING. This value isn't one that's allowed
to be set using the UI, though it is allowed via the API, and the view's
validation code was kicking out the default value.

The fix for the bug was to ensure that we only use the user's existing
bug_notification_level as a default if it's in the set of values that we
allow to appear in the bug_notification_level widget.

I've added a regression test to cover this bug.

To post a comment you must log in.
Revision history for this message
Gavin Panella (allenap) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'lib/lp/bugs/browser/bugsubscription.py'
2--- lib/lp/bugs/browser/bugsubscription.py 2011-02-22 17:17:35 +0000
3+++ lib/lp/bugs/browser/bugsubscription.py 2011-03-04 11:03:47 +0000
4@@ -39,7 +39,7 @@
5 LaunchpadFormView,
6 )
7 from lp.bugs.browser.bug import BugViewMixin
8-from lp.bugs.enum import BugNotificationLevel
9+from lp.bugs.enum import BugNotificationLevel, HIDDEN_BUG_NOTIFICATION_LEVELS
10 from lp.bugs.interfaces.bugsubscription import IBugSubscription
11 from lp.bugs.interfaces.bugtask import IBugTaskSet
12 from lp.services import features
13@@ -118,11 +118,13 @@
14 # drop the NOTHING option since it just makes the UI
15 # confusing.
16 for level in sorted(BugNotificationLevel.items, reverse=True)
17- if level != BugNotificationLevel.NOTHING]
18+ if level not in HIDDEN_BUG_NOTIFICATION_LEVELS]
19 bug_notification_vocabulary = SimpleVocabulary(
20 bug_notification_level_terms)
21
22- if self.current_user_subscription is not None:
23+ if (self.current_user_subscription is not None and
24+ self.current_user_subscription.bug_notification_level not in
25+ HIDDEN_BUG_NOTIFICATION_LEVELS):
26 default_value = (
27 self.current_user_subscription.bug_notification_level)
28 else:
29
30=== modified file 'lib/lp/bugs/browser/tests/test_bugsubscription_views.py'
31--- lib/lp/bugs/browser/tests/test_bugsubscription_views.py 2011-02-22 17:17:35 +0000
32+++ lib/lp/bugs/browser/tests/test_bugsubscription_views.py 2011-03-04 11:03:47 +0000
33@@ -20,6 +20,7 @@
34 set_feature_flag,
35 TestCaseWithFactory,
36 )
37+from lp.testing.views import create_initialized_view
38
39
40 class BugSubscriptionAdvancedFeaturesTestCase(TestCaseWithFactory):
41@@ -250,6 +251,31 @@
42 self.assertFalse(
43 harness.view.widgets['bug_notification_level'].visible)
44
45+ def test_bug_721400(self):
46+ # If a subscription exists with a BugNotificationLevel of
47+ # NOTHING the view will still render correctly, even though
48+ # NOTHING is not accepted as a valid value for the
49+ # bug_notification_level field.
50+ # This is a regression test for bug 721400.
51+ bug = self.factory.makeBug()
52+ person = self.factory.makePerson()
53+ with person_logged_in(person):
54+ subscription = bug.subscribe(
55+ person, person, level=BugNotificationLevel.NOTHING)
56+
57+ with feature_flags():
58+ with person_logged_in(person):
59+ subscribe_view = create_initialized_view(
60+ bug.default_bugtask, name='+subscribe')
61+ self.assertEqual(0, len(subscribe_view.errors))
62+ bug_notification_level_widget = (
63+ subscribe_view.widgets['bug_notification_level'])
64+ default_notification_level_value = (
65+ bug_notification_level_widget._getDefault())
66+ self.assertEqual(
67+ BugNotificationLevel.COMMENTS,
68+ default_notification_level_value)
69+
70
71 class BugPortletSubcribersIdsTests(TestCaseWithFactory):
72
73
74=== modified file 'lib/lp/bugs/enum.py'
75--- lib/lp/bugs/enum.py 2011-02-01 17:52:45 +0000
76+++ lib/lp/bugs/enum.py 2011-03-04 11:03:47 +0000
77@@ -6,6 +6,7 @@
78 __metaclass__ = type
79 __all__ = [
80 'BugNotificationLevel',
81+ 'HIDDEN_BUG_NOTIFICATION_LEVELS',
82 ]
83
84 from lazr.enum import (
85@@ -47,3 +48,7 @@
86 notifications about new events in the bugs's discussion, like new
87 comments.
88 """)
89+
90+
91+# The set of bug notification levels that won't be displayed in the UI.
92+HIDDEN_BUG_NOTIFICATION_LEVELS = [BugNotificationLevel.NOTHING]