on xenial help sign in
Move to main_window.

Update test_notifications.

commitca6ddf2826feedd67db58ab4f3c17a58f01dab1f authorYing-Chun Liu <paul.liu@canonical.com> dateFri 13 Feb 2015, 21:13 (12 years ago) parent3a56805
3 files changed+22−73
tests/autopilot/unity8/shell/__init__.py−63 tests/autopilot/unity8/shell/emulators/main_window.py+16 tests/autopilot/unity8/shell/tests/test_notifications.py+6−10
tests/autopilot/unity8/shell/__init__.py−63
@@ -109,66 +109,3 @@ def _get_urgency(urgency):
109109 'NORMAL': Notify.Urgency.NORMAL,
110110 'CRITICAL': Notify.Urgency.CRITICAL}
111111 return _urgency_enums.get(urgency.upper())
112−
113−def wait_for_notification_dialog(self, timeout):
114− """Wait for a notification dialog to appear.
115−
116− :param int timeout: Maximum amount of time to wait for the notification,
117− in seconds.
118− :return: An autopilot custom proxy object for the notification dialog.
119− :raise StateNotFoundError: if the timeout expires when the
120− notification has not appeared.
121−
122− """
123− notify_list = self.main_window.select_single('Notifications',
124− objectName='notificationList')
125− visible_notification = None
126− for i in range(timeout):
127− notification_list = notify_list.select_many('Notification')
128− visible_notification = None
129− for notification1 in notification_list:
130− if (notification1.visible):
131− visible_notification = notification1
132−
133− if (not visible_notification):
134− if i == timeout - 1:
135− raise dbus.StateNotFoundError
136− else:
137− return visible_notification
138− sleep(1)
139− return visible_notification
140− # Strategy to test the helper:
141− # use the create notification script to verify that the method returns
142− # when a notification is received.
143−
144−class Notification(emulators.UnityEmulatorBase):
145−
146− """Custom proxy object for Notification dialogs."""
147− @classmethod
148− def validate_dbus_object(cls, path, state):
149− name = introspection.get_classname_from_path(path)
150− if name == b'Notification':
151− return True
152− return False
153−
154− def __init__(self, state, path, backend):
155− super(Notification, self).__init__(state, path, backend)
156− # Backup data
157− self._summary = self.summary
158− self._body = self.body
159− self._iconSource = self.iconSource
160−
161−
162− def get_data(self):
163− """Return the contents of a notification dialog.
164−
165− :return: A data object that represents the contents of a notification
166− dialog.
167−
168− """
169− return { 'summary': self._summary,
170− 'body': self._body,
171− 'iconSource': self._iconSource }
172− # Strategy to test the helper:
173− # use the create notification script to get a notification dialog.
174− # Check that the arguments passed to the script match the fields
tests/autopilot/unity8/shell/emulators/main_window.py+16
@@ -174,3 +174,19 @@ class QQuickView(emulators.UnityEmulatorBase):
174174 'PinPadButton',
175175 objectName='pinPadButton{}'.format(button_id)
176176 )
177+
178+ def wait_for_notification_dialog(self):
179+ """Wait for a notification dialog to appear.
180+
181+ :return: An object for the notification dialog data.
182+ :raise StateNotFoundError: if the timeout expires when the
183+ notification has not appeared.
184+
185+ """
186+ notify_list = self.select_single('Notifications',
187+ objectName='notificationList')
188+ visible_notification = notify_list.wait_select_single('Notification',
189+ visible=True)
190+ return { "summary": visible_notification.summary,
191+ "body": visible_notification.body,
192+ "iconSource": visible_notification.iconSource }
tests/autopilot/unity8/shell/tests/test_notifications.py+6−10
@@ -24,7 +24,6 @@ from __future__ import absolute_import
2424from unity8 import shell
2525from unity8.process_helpers import unlock_unity
2626from unity8.shell.tests import UnityTestCase, _get_device_emulation_scenarios
27−from unity8.shell import wait_for_notification_dialog
2827
2928from testtools.matchers import Equals, NotEquals
3029from autopilot.matchers import Eventually
@@ -704,6 +703,9 @@ class EphemeralNotificationsTests(NotificationsBase):
704703 get_notification(), summary, body, False, False, 1.0)
705704
706705 def test_notification_helper(self):
706+ """ use the create notification script to get a notification dialog.
707+ Check that the arguments passed to the script match the fields. """
708+
707709 unity_proxy = self.launch_unity()
708710 unlock_unity(unity_proxy)
709711
@@ -713,13 +715,7 @@ class EphemeralNotificationsTests(NotificationsBase):
713715 notification = shell.create_ephemeral_notification(summary, body)
714716 notification.show()
715717
716− notification = wait_for_notification_dialog(self, 20)
718+ notification_data = self.main_window.wait_for_notification_dialog()
717719
718− self._assert_notification(
719− notification,
720− summary,
721− body,
722− False,
723− False,
724− 1.0
725− )
720+ self.assertThat(notification_data["summary"], Eventually(Equals(summary)))
721+ self.assertThat(notification_data["body"], Eventually(Equals(body)))