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
=== modified file 'tests/autopilot/unity8/shell/__init__.py'
--- tests/autopilot/unity8/shell/__init__.py 2014-02-13 04:13:36 +0000
+++ tests/autopilot/unity8/shell/__init__.py 2014-04-28 14:18:27 +0000
@@ -21,9 +21,10 @@
2121
22from time import sleep22from time import sleep
23from functools import wraps23from functools import wraps
24from gi.repository import Notify
25
24import logging26import logging
2527
26
27logger = logging.getLogger(__name__)28logger = logging.getLogger(__name__)
2829
2930
@@ -48,6 +49,7 @@
48 return fn(*args, **kwargs)49 return fn(*args, **kwargs)
49 return wrapper50 return wrapper
5051
52
51class DragMixin(object):53class DragMixin(object):
52 def _drag(self, x1, y1, x2, y2):54 def _drag(self, x1, y1, x2, y2):
53 # XXX This ugly code is here just temporarily, waiting for drag55 # XXX This ugly code is here just temporarily, waiting for drag
@@ -69,3 +71,50 @@
69 self.touch._finger_move(int(x2), int(y2))71 self.touch._finger_move(int(x2), int(y2))
70 except AttributeError:72 except AttributeError:
71 self.touch._device.finger_move(int(x2), int(y2))73 self.touch._device.finger_move(int(x2), int(y2))
74
75
76def create_ephemeral_notification(
77 summary='',
78 body='',
79 icon=None,
80 hints=[],
81 urgency='NORMAL'
82):
83 """Create an ephemeral (non-interactive) notification
84
85 :param summary: Summary text for the notification
86 :param body: Body text to display in the notification
87 :param icon: Path string to the icon to use
88 :param hint_strings: List of tuples containing the 'name' and value
89 for setting the hint strings for the notification
90 :param urgency: Urgency string for the noticiation, either: 'LOW',
91 'NORMAL', 'CRITICAL'
92 """
93 Notify.init('Unity8')
94
95 logger.info(
96 "Creating ephemeral: summary(%s), body(%s), urgency(%r) "
97 "and Icon(%s)",
98 summary,
99 body,
100 urgency,
101 icon
102 )
103
104 notification = Notify.Notification.new(summary, body, icon)
105
106 for hint in hints:
107 key, value = hint
108 notification.set_hint_string(key, value)
109 logger.info("Adding hint to notification: (%s, %s)", key, value)
110 notification.set_urgency(_get_urgency(urgency))
111
112 return notification
113
114
115def _get_urgency(urgency):
116 """Translates urgency string to enum."""
117 _urgency_enums = {'LOW': Notify.Urgency.LOW,
118 'NORMAL': Notify.Urgency.NORMAL,
119 'CRITICAL': Notify.Urgency.CRITICAL}
120 return _urgency_enums.get(urgency.upper())
72121
=== modified file 'tests/autopilot/unity8/shell/tests/test_notifications.py'
--- tests/autopilot/unity8/shell/tests/test_notifications.py 2014-03-21 14:21:20 +0000
+++ tests/autopilot/unity8/shell/tests/test_notifications.py 2014-04-28 14:18:27 +0000
@@ -21,6 +21,7 @@
2121
22from __future__ import absolute_import22from __future__ import absolute_import
2323
24from unity8 import shell
24from unity8.process_helpers import unlock_unity25from unity8.process_helpers import unlock_unity
25from unity8.shell.tests import UnityTestCase, _get_device_emulation_scenarios26from unity8.shell.tests import UnityTestCase, _get_device_emulation_scenarios
2627
@@ -64,7 +65,8 @@
64 if os.path.abspath(__file__).startswith('/usr/'):65 if os.path.abspath(__file__).startswith('/usr/'):
65 return '/usr/share/unity8/graphics/' + icon_name66 return '/usr/share/unity8/graphics/' + icon_name
66 else:67 else:
67 return os.path.dirname(__file__) + "/../../../../../qml/graphics/" + icon_name68 return os.path.dirname(__file__) + (
69 "/../../../../../qml/graphics/" + icon_name)
6870
69 def _get_notifications_list(self):71 def _get_notifications_list(self):
70 return self.main_window.select_single(72 return self.main_window.select_single(
@@ -354,7 +356,7 @@
354 )356 )
355 ]357 ]
356358
357 notification = self._create_ephemeral_notification(359 notification = shell.create_ephemeral_notification(
358 summary,360 summary,
359 body,361 body,
360 icon_path,362 icon_path,
@@ -391,7 +393,7 @@
391 )393 )
392 ]394 ]
393395
394 notification = self._create_ephemeral_notification(396 notification = shell.create_ephemeral_notification(
395 summary,397 summary,
396 None,398 None,
397 None,399 None,
@@ -433,7 +435,7 @@
433 body_critical = 'Dude, this is so urgent you have no idea :)'435 body_critical = 'Dude, this is so urgent you have no idea :)'
434 icon_path_critical = self._get_icon_path('avatars/anna_olsson.png')436 icon_path_critical = self._get_icon_path('avatars/anna_olsson.png')
435437
436 notification_normal = self._create_ephemeral_notification(438 notification_normal = shell.create_ephemeral_notification(
437 summary_normal,439 summary_normal,
438 body_normal,440 body_normal,
439 icon_path_normal,441 icon_path_normal,
@@ -441,7 +443,7 @@
441 )443 )
442 notification_normal.show()444 notification_normal.show()
443445
444 notification_low = self._create_ephemeral_notification(446 notification_low = shell.create_ephemeral_notification(
445 summary_low,447 summary_low,
446 body_low,448 body_low,
447 icon_path_low,449 icon_path_low,
@@ -449,7 +451,7 @@
449 )451 )
450 notification_low.show()452 notification_low.show()
451453
452 notification_critical = self._create_ephemeral_notification(454 notification_critical = shell.create_ephemeral_notification(
453 summary_critical,455 summary_critical,
454 body_critical,456 body_critical,
455 icon_path_critical,457 icon_path_critical,
@@ -510,7 +512,7 @@
510 summary = 'Summary-Body'512 summary = 'Summary-Body'
511 body = 'This is a superfluous notification'513 body = 'This is a superfluous notification'
512514
513 notification = self._create_ephemeral_notification(summary, body)515 notification = shell.create_ephemeral_notification(summary, body)
514 notification.show()516 notification.show()
515517
516 notification = notify_list.wait_select_single(518 notification = notify_list.wait_select_single(
@@ -534,7 +536,7 @@
534536
535 summary = 'Summary-Only'537 summary = 'Summary-Only'
536538
537 notification = self._create_ephemeral_notification(summary)539 notification = shell.create_ephemeral_notification(summary)
538 notification.show()540 notification.show()
539541
540 notification = notify_list.wait_select_single(542 notification = notify_list.wait_select_single(
@@ -554,7 +556,7 @@
554 body = 'This is the original content of this notification-bubble.'556 body = 'This is the original content of this notification-bubble.'
555 icon_path = self._get_icon_path('avatars/funky.png')557 icon_path = self._get_icon_path('avatars/funky.png')
556558
557 notification = self._create_ephemeral_notification(559 notification = shell.create_ephemeral_notification(
558 summary,560 summary,
559 body,561 body,
560 icon_path562 icon_path
@@ -594,7 +596,7 @@
594 icon_path = self._get_icon_path('avatars/anna_olsson.png')596 icon_path = self._get_icon_path('avatars/anna_olsson.png')
595 hint_icon = self._get_icon_path('applicationIcons/phone-app.png')597 hint_icon = self._get_icon_path('applicationIcons/phone-app.png')
596598
597 notification = self._create_ephemeral_notification(599 notification = shell.create_ephemeral_notification(
598 summary,600 summary,
599 body,601 body,
600 icon_path602 icon_path
@@ -638,7 +640,7 @@
638 body = 'Hey Bro Coly!'640 body = 'Hey Bro Coly!'
639 icon_path = self._get_icon_path('avatars/amanda.png')641 icon_path = self._get_icon_path('avatars/amanda.png')
640 body_sum = body642 body_sum = body
641 notification = self._create_ephemeral_notification(643 notification = shell.create_ephemeral_notification(
642 summary,644 summary,
643 body,645 body,
644 icon_path,646 icon_path,
@@ -674,7 +676,7 @@
674 for new_body in bodies:676 for new_body in bodies:
675 body = new_body677 body = new_body
676 body_sum += '\n' + body678 body_sum += '\n' + body
677 notification = self._create_ephemeral_notification(679 notification = shell.create_ephemeral_notification(
678 summary,680 summary,
679 body,681 body,
680 icon_path,682 icon_path,
@@ -695,48 +697,3 @@
695 False,697 False,
696 1.0698 1.0
697 )699 )
698
699 def _create_ephemeral_notification(
700 self,
701 summary="",
702 body="",
703 icon=None,
704 hints=[],
705 urgency="NORMAL"
706 ):
707 """Create an ephemeral (non-interactive) notification
708
709 :param summary: Summary text for the notification
710 :param body: Body text to display in the notification
711 :param icon: Path string to the icon to use
712 :param hint_strings: List of tuples containing the 'name' and value
713 for setting the hint strings for the notification
714 :param urgency: Urgency string for the noticiation, either: 'LOW',
715 'NORMAL', 'CRITICAL'
716
717 """
718 logger.info(
719 "Creating ephemeral: summary(%s), body(%s), urgency(%r) "
720 "and Icon(%s)",
721 summary,
722 body,
723 urgency,
724 icon
725 )
726
727 n = Notify.Notification.new(summary, body, icon)
728
729 for hint in hints:
730 key, value = hint
731 n.set_hint_string(key, value)
732 logger.info("Adding hint to notification: (%s, %s)", key, value)
733 n.set_urgency(self._get_urgency(urgency))
734
735 return n
736
737 def _get_urgency(self, urgency):
738 """Translates urgency string to enum."""
739 _urgency_enums = {'LOW': Notify.Urgency.LOW,
740 'NORMAL': Notify.Urgency.NORMAL,
741 'CRITICAL': Notify.Urgency.CRITICAL}
742 return _urgency_enums.get(urgency.upper())

Subscribers

People subscribed via source and target branches