Merge lp:~thisfred/ubuntuone-client/use-single-notification into lp:ubuntuone-client

Proposed by Eric Casteleijn on 2011-03-03
Status: Merged
Approved by: dobey on 2011-03-07
Approved revision: 908
Merged at revision: 906
Proposed branch: lp:~thisfred/ubuntuone-client/use-single-notification
Merge into: lp:ubuntuone-client
Diff against target: 255 lines (+29/-110)
6 files modified
tests/platform/linux/test_notification.py (+17/-21)
tests/status/test_aggregator.py (+2/-56)
ubuntuone/platform/linux/notification.py (+8/-12)
ubuntuone/platform/windows/notification.py (+0/-5)
ubuntuone/status/aggregator.py (+2/-11)
ubuntuone/status/notification.py (+0/-5)
To merge this branch: bzr merge lp:~thisfred/ubuntuone-client/use-single-notification
Reviewer Review Type Date Requested Status
dobey (community) Approve on 2011-03-07
Natalia Bidart 2011-03-03 Approve on 2011-03-04
Review via email: mp+52147@code.launchpad.net

Commit message

use a single pynotify.Notification instance

Description of the change

use a single pynotify.Notification instance

To post a comment you must log in.
Natalia Bidart (nataliabidart) wrote :

Very good!

review: Approve
dobey (dobey) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/platform/linux/test_notification.py'
2--- tests/platform/linux/test_notification.py 2011-02-11 18:27:00 +0000
3+++ tests/platform/linux/test_notification.py 2011-03-03 23:40:12 +0000
4@@ -63,6 +63,22 @@
5 self.mocker.replay()
6 Notification(FAKE_APP_NAME).send_notification(FAKE_TITLE, FAKE_MESSAGE)
7
8+ def test_send_two_notifications(self):
9+ """On notification, pynotify receives the proper calls."""
10+ mock_notify = self.mocker.replace("pynotify")
11+ mock_notify.init(FAKE_APP_NAME)
12+ mock_notify.Notification(FAKE_TITLE, FAKE_MESSAGE, ICON_NAME)
13+ mock_notification = self.mocker.mock()
14+ self.mocker.result(mock_notification)
15+ mock_notification.show()
16+ mock_notification.update(
17+ FAKE_TITLE + '2', FAKE_MESSAGE + '2', ICON_NAME)
18+ mock_notification.show()
19+ self.mocker.replay()
20+ notifier = Notification(FAKE_APP_NAME)
21+ notifier.send_notification(FAKE_TITLE, FAKE_MESSAGE)
22+ notifier.send_notification(FAKE_TITLE + '2', FAKE_MESSAGE + '2')
23+
24 def test_send_notification_with_icon(self):
25 """On notification with icon, pynotify receives the proper calls."""
26 mock_notify = self.mocker.replace("pynotify")
27@@ -84,30 +100,10 @@
28 self.mocker.result(mock_notification)
29 mock_notification.set_hint_string('x-canonical-append', '')
30 mock_notification.show()
31- mock_notify.init(FAKE_APP_NAME)
32- mock_notify.Notification(FAKE_TITLE, FAKE_APPENDAGE, ICON_NAME)
33- mock_notification = self.mocker.mock()
34- self.mocker.result(mock_notification)
35+ mock_notification.update(FAKE_TITLE, FAKE_APPENDAGE, ICON_NAME)
36 mock_notification.set_hint_string('x-canonical-append', '')
37 mock_notification.show()
38 self.mocker.replay()
39 notifier = Notification(FAKE_APP_NAME)
40 notifier.send_notification(FAKE_TITLE, FAKE_MESSAGE, append=True)
41 notifier.send_notification(FAKE_TITLE, FAKE_APPENDAGE, append=True)
42-
43- def test_update_notification(self):
44- """On notification update, pynotify receives the proper calls."""
45- mock_notify = self.mocker.replace("pynotify")
46- mock_notify.init(FAKE_APP_NAME)
47- mock_notify.Notification(FAKE_TITLE, FAKE_MESSAGE, ICON_NAME)
48- mock_notification = self.mocker.mock()
49- self.mocker.result(mock_notification)
50- mock_notification.show()
51- mock_notification.update(
52- FAKE_NEW_TITLE, FAKE_NEW_MESSAGE, FAKE_NEW_ICON)
53- mock_notification.show()
54- self.mocker.replay()
55- notifier = Notification(FAKE_APP_NAME)
56- notification = notifier.send_notification(FAKE_TITLE, FAKE_MESSAGE)
57- notifier.update_notification(
58- notification, FAKE_NEW_TITLE, FAKE_NEW_MESSAGE, FAKE_NEW_ICON)
59
60=== modified file 'tests/status/test_aggregator.py'
61--- tests/status/test_aggregator.py 2011-02-24 20:09:56 +0000
62+++ tests/status/test_aggregator.py 2011-03-03 23:40:12 +0000
63@@ -136,31 +136,17 @@
64 self.notifications_shown = []
65 self.notification_switch = None
66 self.application_name = application_name
67+ self.notification = None
68
69 def send_notification(self, title, message, icon=None, append=False):
70 """Show a notification to the user."""
71 if (self.notification_switch is not None
72 and not self.notification_switch.enabled):
73 return
74+ self.notification = (title, message, icon, append)
75 self.notifications_shown.append((title, message, icon, append))
76 return len(self.notifications_shown) - 1
77
78- def update_notification(self, notification_id, new_title, new_message,
79- new_icon=None):
80- """Update the notification with a new message body."""
81- if (self.notification_switch is not None
82- and not self.notification_switch.enabled):
83- return
84- if notification_id is None:
85- return
86- title, old_message, icon, append = self.notifications_shown[
87- notification_id]
88- if new_icon is not None:
89- icon = new_icon
90- # we store it as a new notification, to ease testing
91- notification_params = (new_title, new_message, icon, append)
92- self.notifications_shown.append(notification_params)
93-
94
95 def FakeNotificationSingleton():
96 """Builds a notification singleton, that logs all notifications shown."""
97@@ -263,15 +249,6 @@
98 self.toggleable.send_notification(*args)
99 self.assertShown(args)
100
101- def test_update_notification_passes_thru(self):
102- """The update_notification method passes thru."""
103- show_args = ("title", "body", "icon", "append")
104- update_args = ("other title", "other body")
105- expected = update_args + show_args[2:]
106- notification_id = self.toggleable.send_notification(*show_args)
107- self.toggleable.update_notification(notification_id, *update_args)
108- self.assertShown(expected)
109-
110 def test_send_notification_honored_when_enabled(self):
111 """The send_notification method is honored when enabled."""
112 self.notification_switch.enable_notifications()
113@@ -286,37 +263,6 @@
114 self.toggleable.send_notification(*args)
115 self.assertNotShown(args)
116
117- def test_update_notification_honored_when_enabled(self):
118- """The update_notification method is honored when enabled."""
119- self.notification_switch.enable_notifications()
120- show_args = ("title", "body", "icon", "append")
121- update_args = ("other title", "other body")
122- expected = update_args + show_args[2:]
123- notification_id = self.toggleable.send_notification(*show_args)
124- self.toggleable.update_notification(notification_id, *update_args)
125- self.assertShown(expected)
126-
127- def test_update_notification_ignored_when_disabled(self):
128- """The update_notification method is ignored when disabled."""
129- self.notification_switch.disable_notifications()
130- show_args = ("title", "body", "icon", "append")
131- update_args = ("other title", "other body")
132- expected = update_args + show_args[2:]
133- notification_id = self.toggleable.send_notification(*show_args)
134- self.toggleable.update_notification(notification_id, *update_args)
135- self.assertNotShown(expected)
136-
137- def test_update_after_disabled_show(self):
138- """An update is ignored if the corresponding show was disabled."""
139- self.notification_switch.disable_notifications()
140- show_args = ("title", "body", "icon", "append")
141- update_args = ("other title", "other body")
142- expected = update_args + show_args[2:]
143- notification_id = self.toggleable.send_notification(*show_args)
144- self.notification_switch.enable_notifications()
145- self.toggleable.update_notification(notification_id, *update_args)
146- self.assertNotShown(expected)
147-
148
149 class NotificationSwitchTestCase(TestCase):
150 """Test the NotificationSwitch class."""
151
152=== modified file 'ubuntuone/platform/linux/notification.py'
153--- ubuntuone/platform/linux/notification.py 2011-02-11 18:27:00 +0000
154+++ ubuntuone/platform/linux/notification.py 2011-03-03 23:40:12 +0000
155@@ -39,21 +39,17 @@
156 # pylint: disable=W0231
157 def __init__(self, application_name=APPLICATION_NAME):
158 self.application_name = application_name
159+ self.notification = None
160 # pylint: enable=W0231
161
162 def send_notification(self, title, message, icon=ICON_NAME, append=False):
163 """Send a notification using the underlying library."""
164 if USE_PYNOTIFY:
165- pynotify.init(self.application_name)
166- notification = pynotify.Notification(title, message, icon)
167+ if self.notification is None:
168+ pynotify.init(self.application_name)
169+ self.notification = pynotify.Notification(title, message, icon)
170+ else:
171+ self.notification.update(title, message, icon)
172 if append:
173- notification.set_hint_string('x-canonical-append', '')
174- notification.show()
175- return notification
176-
177- def update_notification(self, notification, new_title, new_message,
178- new_icon=ICON_NAME):
179- """Update the notification with a new message body."""
180- if USE_PYNOTIFY:
181- notification.update(new_title, new_message, new_icon)
182- notification.show()
183+ self.notification.set_hint_string('x-canonical-append', '')
184+ self.notification.show()
185
186=== modified file 'ubuntuone/platform/windows/notification.py'
187--- ubuntuone/platform/windows/notification.py 2011-02-01 14:33:43 +0000
188+++ ubuntuone/platform/windows/notification.py 2011-03-03 23:40:12 +0000
189@@ -34,8 +34,3 @@
190 """Send a notification using the underlying library."""
191 # TODO: Send notifications. Dummy class is here to not break
192 # on windows.
193-
194- def update_notification(self, notification, new_title, new_message,
195- new_icon=None):
196- """Update the notification with a new message body."""
197-
198
199=== modified file 'ubuntuone/status/aggregator.py'
200--- ubuntuone/status/aggregator.py 2011-02-24 20:09:56 +0000
201+++ ubuntuone/status/aggregator.py 2011-03-03 23:40:12 +0000
202@@ -112,12 +112,6 @@
203 if self.notification_switch.enabled:
204 return self.notification.send_notification(*args)
205
206- def update_notification(self, notification_id, *args):
207- """Passthru the update."""
208- if notification_id is not None and self.notification_switch.enabled:
209- return self.notification.update_notification(notification_id,
210- *args)
211-
212
213 class NotificationSwitch(object):
214 """A switch that turns notifications on and off."""
215@@ -400,7 +394,6 @@
216 """
217
218 state = None
219- last_notification_id = 0
220
221 def __init__(self, status_aggregator, clock=reactor):
222 """Initialize this instance."""
223@@ -426,8 +419,7 @@
224 def _popup(self):
225 """Display the notification."""
226 text = self.status_aggregator.get_discovery_message()
227- self.last_notification_id = self.notification.send_notification(
228- UBUNTUONE_TITLE, text)
229+ self.notification.send_notification(UBUNTUONE_TITLE, text)
230 self.status_aggregator.restart_progress_bubble()
231 logger.debug("notification shown: %s", text)
232 self._change_state(FileDiscoveryUpdateState)
233@@ -437,8 +429,7 @@
234 text = self.status_aggregator.get_discovery_message()
235 logger.debug("notification updated: %s", text)
236 self.status_aggregator.restart_progress_bubble()
237- self.notification.update_notification(self.last_notification_id,
238- UBUNTUONE_TITLE, text)
239+ self.notification.send_notification(UBUNTUONE_TITLE, text)
240
241 def start_sleeping(self):
242 """Wait for 10 minutes before annoying again."""
243
244=== modified file 'ubuntuone/status/notification.py'
245--- ubuntuone/status/notification.py 2011-02-01 19:07:16 +0000
246+++ ubuntuone/status/notification.py 2011-03-03 23:40:12 +0000
247@@ -30,8 +30,3 @@
248 @abstractmethod
249 def send_notification(self, title, message, icon=None, append=False):
250 """Send a notification to the end user."""
251-
252- @abstractmethod
253- def update_notification(self, notification, new_title, new_message,
254- new_icon=None):
255- """Update the notification with a new message body."""

Subscribers

People subscribed via source and target branches