Merge lp:~vrruiz/unity8/helpers-notify into lp:unity8

Proposed by Víctor R. Ruiz
Status: Merged
Approved by: Andrea Cimitan
Approved revision: 825
Merged at revision: 867
Proposed branch: lp:~vrruiz/unity8/helpers-notify
Merge into: lp:unity8
Diff against target: 244 lines (+64/-58)
2 files modified
tests/autopilot/unity8/shell/__init__.py (+50/-1)
tests/autopilot/unity8/shell/tests/test_notifications.py (+14/-57)
To merge this branch: bzr merge lp:~vrruiz/unity8/helpers-notify
Reviewer Review Type Date Requested Status
Michał Sawicz Needs Fixing
Andrea Cimitan (community) Approve
PS Jenkins bot (community) continuous-integration Needs Fixing
Leo Arias (community) code review Approve
Allan LeSage (community) Needs Fixing
Richard Huddie Pending
Review via email: mp+215700@code.launchpad.net

Commit message

Move autopilot notification code to a helper method.

Description of the change

Move autopilot notification code to a helper method.

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:824
http://jenkins.qa.ubuntu.com/job/unity8-ci/2816/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-trusty-touch/234
    UNSTABLE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-trusty/4826
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity-phablet-qmluitests-trusty/1680
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-amd64-ci/1337
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-armhf-ci/1341
        deb: http://jenkins.qa.ubuntu.com/job/unity8-trusty-armhf-ci/1341/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-i386-ci/1337
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-runner-mako/221
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-armhf/4403
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-armhf/4403/artifact/work/output/*zip*/output.zip
    SUCCESS: http://s-jenkins.ubuntu-ci:8080/job/touch-flash-device/6006
    UNSTABLE: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-trusty/4171
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-amd64/4958
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-amd64/4958/artifact/work/output/*zip*/output.zip

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/unity8-ci/2816/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Allan LeSage (allanlesage) wrote :

Get the PITA out of the way:

38-45: Comments to the left by four spaces (although I see in the prior commit ;) ).
93-94: IMO it's better to use parentheses to join these broken lines.

On the whole it's nice small change and more convenient, looks good.

review: Needs Fixing
lp:~vrruiz/unity8/helpers-notify updated
825. By Víctor R. Ruiz

Autopilot: Style fixes

Revision history for this message
Víctor R. Ruiz (vrruiz) wrote :

Thanks for the comments, Allan. Changes done.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :

FAILED: Continuous integration, rev:825
http://jenkins.qa.ubuntu.com/job/unity8-ci/2840/
Executed test runs:
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-trusty-touch/298
    FAILURE: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-trusty/4909/console
    UNSTABLE: http://jenkins.qa.ubuntu.com/job/unity-phablet-qmluitests-trusty/1704
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-amd64-ci/1361
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-armhf-ci/1365
        deb: http://jenkins.qa.ubuntu.com/job/unity8-trusty-armhf-ci/1365/artifact/work/output/*zip*/output.zip
    SUCCESS: http://jenkins.qa.ubuntu.com/job/unity8-trusty-i386-ci/1361
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-deb-autopilot-runner-mako/280
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-armhf/4487
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-armhf/4487/artifact/work/output/*zip*/output.zip
    SUCCESS: http://s-jenkins.ubuntu-ci:8080/job/touch-flash-device/6130
    FAILURE: http://jenkins.qa.ubuntu.com/job/autopilot-testrunner-otto-trusty/4241/console
    SUCCESS: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-amd64/5054
        deb: http://jenkins.qa.ubuntu.com/job/generic-mediumtests-builder-trusty-amd64/5054/artifact/work/output/*zip*/output.zip

Click here to trigger a rebuild:
http://s-jenkins.ubuntu-ci:8080/job/unity8-ci/2840/rebuild

review: Needs Fixing (continuous-integration)
Revision history for this message
Leo Arias (elopio) wrote :

Please add to the description of your MP the dev checklist from:
https://wiki.ubuntu.com/Process/Merges/Checklists/Unity8

review: Approve (code review)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Víctor R. Ruiz (vrruiz) wrote :

* Are there any related MPs required for this MP to build/function as expected? Please list.
- No.

* Did you perform an exploratory manual test run of your code change and any related functionality?
- Yes.

* Did you make sure that your branch does not contain spurious tags?
- Yes.

* If you changed the packaging (debian), did you subscribe the ubuntu-unity team to this MP?
- No changes.

* If you changed the UI, has there been a design review?
- No changes.

Revision history for this message
Andrea Cimitan (cimi) wrote :

 * Did you perform an exploratory manual test run of the code change and any related functionality?
Yes
 * Did CI run pass? If not, please explain why.
Unrelated

review: Approve
Revision history for this message
Michał Sawicz (saviq) wrote :
review: Needs Fixing
lp:~vrruiz/unity8/helpers-notify updated
826. By Víctor R. Ruiz

Strip tags

Revision history for this message
Víctor R. Ruiz (vrruiz) wrote :

Michal: Done!

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'tests/autopilot/unity8/shell/__init__.py'
2--- tests/autopilot/unity8/shell/__init__.py 2014-02-13 04:13:36 +0000
3+++ tests/autopilot/unity8/shell/__init__.py 2014-04-28 14:18:27 +0000
4@@ -21,9 +21,10 @@
5
6 from time import sleep
7 from functools import wraps
8+from gi.repository import Notify
9+
10 import logging
11
12-
13 logger = logging.getLogger(__name__)
14
15
16@@ -48,6 +49,7 @@
17 return fn(*args, **kwargs)
18 return wrapper
19
20+
21 class DragMixin(object):
22 def _drag(self, x1, y1, x2, y2):
23 # XXX This ugly code is here just temporarily, waiting for drag
24@@ -69,3 +71,50 @@
25 self.touch._finger_move(int(x2), int(y2))
26 except AttributeError:
27 self.touch._device.finger_move(int(x2), int(y2))
28+
29+
30+def create_ephemeral_notification(
31+ summary='',
32+ body='',
33+ icon=None,
34+ hints=[],
35+ urgency='NORMAL'
36+):
37+ """Create an ephemeral (non-interactive) notification
38+
39+ :param summary: Summary text for the notification
40+ :param body: Body text to display in the notification
41+ :param icon: Path string to the icon to use
42+ :param hint_strings: List of tuples containing the 'name' and value
43+ for setting the hint strings for the notification
44+ :param urgency: Urgency string for the noticiation, either: 'LOW',
45+ 'NORMAL', 'CRITICAL'
46+ """
47+ Notify.init('Unity8')
48+
49+ logger.info(
50+ "Creating ephemeral: summary(%s), body(%s), urgency(%r) "
51+ "and Icon(%s)",
52+ summary,
53+ body,
54+ urgency,
55+ icon
56+ )
57+
58+ notification = Notify.Notification.new(summary, body, icon)
59+
60+ for hint in hints:
61+ key, value = hint
62+ notification.set_hint_string(key, value)
63+ logger.info("Adding hint to notification: (%s, %s)", key, value)
64+ notification.set_urgency(_get_urgency(urgency))
65+
66+ return notification
67+
68+
69+def _get_urgency(urgency):
70+ """Translates urgency string to enum."""
71+ _urgency_enums = {'LOW': Notify.Urgency.LOW,
72+ 'NORMAL': Notify.Urgency.NORMAL,
73+ 'CRITICAL': Notify.Urgency.CRITICAL}
74+ return _urgency_enums.get(urgency.upper())
75
76=== modified file 'tests/autopilot/unity8/shell/tests/test_notifications.py'
77--- tests/autopilot/unity8/shell/tests/test_notifications.py 2014-03-21 14:21:20 +0000
78+++ tests/autopilot/unity8/shell/tests/test_notifications.py 2014-04-28 14:18:27 +0000
79@@ -21,6 +21,7 @@
80
81 from __future__ import absolute_import
82
83+from unity8 import shell
84 from unity8.process_helpers import unlock_unity
85 from unity8.shell.tests import UnityTestCase, _get_device_emulation_scenarios
86
87@@ -64,7 +65,8 @@
88 if os.path.abspath(__file__).startswith('/usr/'):
89 return '/usr/share/unity8/graphics/' + icon_name
90 else:
91- return os.path.dirname(__file__) + "/../../../../../qml/graphics/" + icon_name
92+ return os.path.dirname(__file__) + (
93+ "/../../../../../qml/graphics/" + icon_name)
94
95 def _get_notifications_list(self):
96 return self.main_window.select_single(
97@@ -354,7 +356,7 @@
98 )
99 ]
100
101- notification = self._create_ephemeral_notification(
102+ notification = shell.create_ephemeral_notification(
103 summary,
104 body,
105 icon_path,
106@@ -391,7 +393,7 @@
107 )
108 ]
109
110- notification = self._create_ephemeral_notification(
111+ notification = shell.create_ephemeral_notification(
112 summary,
113 None,
114 None,
115@@ -433,7 +435,7 @@
116 body_critical = 'Dude, this is so urgent you have no idea :)'
117 icon_path_critical = self._get_icon_path('avatars/anna_olsson.png')
118
119- notification_normal = self._create_ephemeral_notification(
120+ notification_normal = shell.create_ephemeral_notification(
121 summary_normal,
122 body_normal,
123 icon_path_normal,
124@@ -441,7 +443,7 @@
125 )
126 notification_normal.show()
127
128- notification_low = self._create_ephemeral_notification(
129+ notification_low = shell.create_ephemeral_notification(
130 summary_low,
131 body_low,
132 icon_path_low,
133@@ -449,7 +451,7 @@
134 )
135 notification_low.show()
136
137- notification_critical = self._create_ephemeral_notification(
138+ notification_critical = shell.create_ephemeral_notification(
139 summary_critical,
140 body_critical,
141 icon_path_critical,
142@@ -510,7 +512,7 @@
143 summary = 'Summary-Body'
144 body = 'This is a superfluous notification'
145
146- notification = self._create_ephemeral_notification(summary, body)
147+ notification = shell.create_ephemeral_notification(summary, body)
148 notification.show()
149
150 notification = notify_list.wait_select_single(
151@@ -534,7 +536,7 @@
152
153 summary = 'Summary-Only'
154
155- notification = self._create_ephemeral_notification(summary)
156+ notification = shell.create_ephemeral_notification(summary)
157 notification.show()
158
159 notification = notify_list.wait_select_single(
160@@ -554,7 +556,7 @@
161 body = 'This is the original content of this notification-bubble.'
162 icon_path = self._get_icon_path('avatars/funky.png')
163
164- notification = self._create_ephemeral_notification(
165+ notification = shell.create_ephemeral_notification(
166 summary,
167 body,
168 icon_path
169@@ -594,7 +596,7 @@
170 icon_path = self._get_icon_path('avatars/anna_olsson.png')
171 hint_icon = self._get_icon_path('applicationIcons/phone-app.png')
172
173- notification = self._create_ephemeral_notification(
174+ notification = shell.create_ephemeral_notification(
175 summary,
176 body,
177 icon_path
178@@ -638,7 +640,7 @@
179 body = 'Hey Bro Coly!'
180 icon_path = self._get_icon_path('avatars/amanda.png')
181 body_sum = body
182- notification = self._create_ephemeral_notification(
183+ notification = shell.create_ephemeral_notification(
184 summary,
185 body,
186 icon_path,
187@@ -674,7 +676,7 @@
188 for new_body in bodies:
189 body = new_body
190 body_sum += '\n' + body
191- notification = self._create_ephemeral_notification(
192+ notification = shell.create_ephemeral_notification(
193 summary,
194 body,
195 icon_path,
196@@ -695,48 +697,3 @@
197 False,
198 1.0
199 )
200-
201- def _create_ephemeral_notification(
202- self,
203- summary="",
204- body="",
205- icon=None,
206- hints=[],
207- urgency="NORMAL"
208- ):
209- """Create an ephemeral (non-interactive) notification
210-
211- :param summary: Summary text for the notification
212- :param body: Body text to display in the notification
213- :param icon: Path string to the icon to use
214- :param hint_strings: List of tuples containing the 'name' and value
215- for setting the hint strings for the notification
216- :param urgency: Urgency string for the noticiation, either: 'LOW',
217- 'NORMAL', 'CRITICAL'
218-
219- """
220- logger.info(
221- "Creating ephemeral: summary(%s), body(%s), urgency(%r) "
222- "and Icon(%s)",
223- summary,
224- body,
225- urgency,
226- icon
227- )
228-
229- n = Notify.Notification.new(summary, body, icon)
230-
231- for hint in hints:
232- key, value = hint
233- n.set_hint_string(key, value)
234- logger.info("Adding hint to notification: (%s, %s)", key, value)
235- n.set_urgency(self._get_urgency(urgency))
236-
237- return n
238-
239- def _get_urgency(self, urgency):
240- """Translates urgency string to enum."""
241- _urgency_enums = {'LOW': Notify.Urgency.LOW,
242- 'NORMAL': Notify.Urgency.NORMAL,
243- 'CRITICAL': Notify.Urgency.CRITICAL}
244- return _urgency_enums.get(urgency.upper())

Subscribers

People subscribed via source and target branches