Lomiri
Loading...
Searching...
No Matches
lomiri.shell.tests.test_notifications.InteractiveNotificationBase Class Reference
Inheritance diagram for lomiri.shell.tests.test_notifications.InteractiveNotificationBase:
Collaboration diagram for lomiri.shell.tests.test_notifications.InteractiveNotificationBase:

Public Member Functions

 setUp (self)
 
 test_interactive (self)
 
 test_sd_one_over_two_layout (self)
 
 test_modal_sd_without_greeter (self)
 
 test_modal_sd_with_greeter (self)
 
 assert_notification_action_id_was_called (self, action_id, timeout=10)
 
- Public Member Functions inherited from lomiri.shell.tests.LomiriTestCase
 setUpClass (cls)
 
 launch_lomiri (self, mode="full-greeter", *args)
 
 patch_lightdm_mock (self)
 
 wait_for_lomiri (self)
 
 get_dash (self)
 
 main_window (self)
 

Protected Member Functions

 _create_interactive_notification (self, summary="", body="", icon=None, urgency="NORMAL", actions=[], hints=[])
 
 _get_notify_script (self)
 
 _tidy_up_script_process (self)
 
- Protected Member Functions inherited from lomiri.shell.tests.test_notifications.NotificationsBase
 _get_icon_path (self, icon_name)
 
 _get_notifications_list (self)
 
 _assert_notification (self, notification, summary=None, body=None, icon=True, secondary_icon=False, opacity=None)
 
- Protected Member Functions inherited from lomiri.shell.tests.LomiriTestCase
 _setup_display_details (self)
 
 _determine_geometry (self)
 
 _setup_grid_size (self, scale_divisor)
 
 _geo_larger_than_display (self, width, height)
 
 _get_scaled_down_geo (self, width, height)
 
 _launch_lomiri_with_upstart (self, binary_path, args)
 
 _patch_data_dirs (self)
 
 _get_lightdm_mock_path (self)
 
 _set_proxy (self, proxy)
 
 _clear_proxy (self)
 

Protected Attributes

 _notify_proc
 
 _tidy_up_script_process
 
- Protected Attributes inherited from lomiri.shell.tests.LomiriTestCase
 _proxy
 
 _qml_mock_enabled
 
 _data_dirs_mock_enabled
 
 _environment
 
 _clear_proxy
 

Additional Inherited Members

- Public Attributes inherited from lomiri.shell.tests.LomiriTestCase
 lomiri_geometry_args
 
 grid_size
 
- Static Public Attributes inherited from lomiri.shell.tests.test_notifications.NotificationsBase
 scenarios
 

Detailed Description

Collection of test for Interactive tests including snap decisions.

Definition at line 112 of file test_notifications.py.

Member Function Documentation

◆ _create_interactive_notification()

lomiri.shell.tests.test_notifications.InteractiveNotificationBase._create_interactive_notification (   self,
  summary = "",
  body = "",
  icon = None,
  urgency = "NORMAL",
  actions = [],
  hints = [] 
)
protected
Create a interactive notification command.

:param summary: Summary text for the notification
:param body: Body text to display in the notification
:param icon: Path string to the icon to use
:param urgency: Urgency string for the noticiation, either: 'LOW',
    'NORMAL', 'CRITICAL'
:param actions: List of tuples containing the 'id' and 'label' for all
    the actions to add
:param hint_strings: List of tuples containing the 'name' and value for
    setting the hint strings for the notification

Definition at line 293 of file test_notifications.py.

301 ):
302 """Create a interactive notification command.
303
304 :param summary: Summary text for the notification
305 :param body: Body text to display in the notification
306 :param icon: Path string to the icon to use
307 :param urgency: Urgency string for the noticiation, either: 'LOW',
308 'NORMAL', 'CRITICAL'
309 :param actions: List of tuples containing the 'id' and 'label' for all
310 the actions to add
311 :param hint_strings: List of tuples containing the 'name' and value for
312 setting the hint strings for the notification
313
314 """
315
316 logger.info(
317 "Creating snap-decision notification with summary(%s), body(%s) "
318 "and urgency(%r)",
319 summary,
320 body,
321 urgency
322 )
323
324 script_args = [
325 '--summary', summary,
326 '--body', body,
327 '--urgency', urgency
328 ]
329
330 if icon is not None:
331 script_args.extend(['--icon', icon])
332
333 for hint in hints:
334 key, value = hint
335 script_args.extend(['--hint', "%s,%s" % (key, value)])
336
337 for action in actions:
338 action_id, action_label = action
339 action_string = "%s,%s" % (action_id, action_label)
340 script_args.extend(['--action', action_string])
341
342 python_bin = subprocess.check_output(['which', 'python3']).strip()
343 command = [python_bin, self._get_notify_script()] + script_args
344 logger.info("Launching snap-decision notification as: %s", command)
345 self._notify_proc = subprocess.Popen(
346 command,
347 stdin=subprocess.PIPE,
348 stdout=subprocess.PIPE,
349 stderr=subprocess.PIPE,
350 close_fds=True,
351 universal_newlines=True,
352 )
353
354 self.addCleanup(self._tidy_up_script_process)
355
356 poll_result = self._notify_proc.poll()
357 if poll_result is not None and self._notify_proc.returncode != 0:
358 error_output = self._notify_proc.communicate()[1]
359 raise RuntimeError("Call to script failed with: %s" % error_output)
360

◆ _get_notify_script()

lomiri.shell.tests.test_notifications.InteractiveNotificationBase._get_notify_script (   self)
protected
Returns the path to the interactive notification
   creation script.

Definition at line 361 of file test_notifications.py.

361 def _get_notify_script(self):
362 """Returns the path to the interactive notification
363 creation script.
364 """
365 file_path = "../../create_interactive_notification.py"
366
367 the_path = os.path.abspath(
368 os.path.join(__file__, file_path))
369
370 return the_path
371

◆ _tidy_up_script_process()

lomiri.shell.tests.test_notifications.InteractiveNotificationBase._tidy_up_script_process (   self)
protected

Definition at line 372 of file test_notifications.py.

372 def _tidy_up_script_process(self):
373 if self._notify_proc is not None and self._notify_proc.poll() is None:
374 logger.error("Notification process wasn't killed, killing now.")
375 os.killpg(self._notify_proc.pid, signal.SIGTERM)
376

◆ assert_notification_action_id_was_called()

lomiri.shell.tests.test_notifications.InteractiveNotificationBase.assert_notification_action_id_was_called (   self,
  action_id,
  timeout = 10 
)
Assert that the interactive notification callback of id *action_id*
was called.

:raises AssertionError: If no interactive notification has actually
    been created.
:raises AssertionError: When *action_id* does not match the actual
    returned.
:raises AssertionError: If no callback was called at all.

Definition at line 377 of file test_notifications.py.

377 def assert_notification_action_id_was_called(self, action_id, timeout=10):
378 """Assert that the interactive notification callback of id *action_id*
379 was called.
380
381 :raises AssertionError: If no interactive notification has actually
382 been created.
383 :raises AssertionError: When *action_id* does not match the actual
384 returned.
385 :raises AssertionError: If no callback was called at all.
386 """
387
388 if self._notify_proc is None:
389 raise AssertionError("No interactive notification was created.")
390
391 for i in range(timeout):
392 self._notify_proc.poll()
393 if self._notify_proc.returncode is not None:
394 output = self._notify_proc.communicate()
395 actual_action_id = output[0].strip("\n")
396 if actual_action_id != action_id:
397 raise AssertionError(
398 "action id '%s' does not match actual returned '%s'"
399 % (action_id, actual_action_id)
400 )
401 else:
402 return
403 time.sleep(1)
404
405 os.killpg(self._notify_proc.pid, signal.SIGTERM)
406 self._notify_proc = None
407 raise AssertionError(
408 "No callback was called, killing interactivenotification script"
409 )
410
411

◆ setUp()

lomiri.shell.tests.test_notifications.InteractiveNotificationBase.setUp (   self)

Reimplemented from lomiri.shell.tests.LomiriTestCase.

Definition at line 115 of file test_notifications.py.

115 def setUp(self):
116 super().setUp()
117 # Need to keep track when we launch the notification script.
118 self._notify_proc = None
119

◆ test_interactive()

lomiri.shell.tests.test_notifications.InteractiveNotificationBase.test_interactive (   self)
Interactive notification must react upon click on itself.

Definition at line 120 of file test_notifications.py.

120 def test_interactive(self):
121 """Interactive notification must react upon click on itself."""
122 self.launch_lomiri()
123 unlock_lomiri()
124
125 notify_list = self._get_notifications_list()
126
127 summary = "Interactive notification"
128 body = "This notification can be clicked on to trigger an action."
129 icon_path = self._get_icon_path('avatars/anna_olsson.png')
130 actions = [("action_id", "dummy")]
131 hints = [
132 ("x-lomiri-switch-to-application", "true"),
133 ("x-lomiri-secondary-icon", "dialer")
134 ]
135
136 self._create_interactive_notification(
137 summary,
138 body,
139 icon_path,
140 "NORMAL",
141 actions,
142 hints,
143 )
144
145 get_notification = lambda: notify_list.wait_select_single(
146 'Notification', objectName='notification0')
147 notification = get_notification()
148
149 notification.pointing_device.click_object(
150 notification.select_single(objectName="interactiveArea")
151 )
152
153 self.assert_notification_action_id_was_called('action_id')
154

◆ test_modal_sd_with_greeter()

lomiri.shell.tests.test_notifications.InteractiveNotificationBase.test_modal_sd_with_greeter (   self)
A snap-decision should block input to the
   greeter/lockscreen beneath it.

Definition at line 245 of file test_notifications.py.

245 def test_modal_sd_with_greeter(self):
246 """A snap-decision should block input to the
247 greeter/lockscreen beneath it.
248 """
249 self.launch_lomiri()
250
251 summary = "Incoming file"
252 body = "Frank would like to send you the file: essay.pdf"
253 icon_path = "sync-idle"
254 hints = [
255 ("x-lomiri-snap-decisions", "true"),
256 ("x-lomiri-non-shaped-icon", "true"),
257 ("x-lomiri-private-affirmative-tint", "true"),
258 ("x-lomiri-private-rejection-tint", "true"),
259 ]
260
261 actions = [
262 ('action_accept', 'Accept'),
263 ('action_decline_1', 'Decline'),
264 ]
265
266 self._create_interactive_notification(
267 summary,
268 body,
269 icon_path,
270 "NORMAL",
271 actions,
272 hints
273 )
274
275 # verify that we cannot reveal the launcher (no longer interact with
276 # the shell)
277 time.sleep(1)
278 self.main_window.show_dash_swiping()
279 self.assertThat(
280 self.main_window.is_launcher_open, Eventually(Equals(False)))
281
282 # verify and interact with the triggered snap-decision notification
283 notify_list = self._get_notifications_list()
284 get_notification = lambda: notify_list.wait_select_single(
285 'Notification', objectName='notification0')
286 notification = get_notification()
287 self._assert_notification(
288 notification, summary, body, True, False, 1.0)
289 notification.pointing_device.click_object(
290 notification.select_single(objectName="notify_button0"))
291 self.assert_notification_action_id_was_called("action_accept")
292

◆ test_modal_sd_without_greeter()

lomiri.shell.tests.test_notifications.InteractiveNotificationBase.test_modal_sd_without_greeter (   self)
Snap-decision should block input to shell
   without greeter/lockscreen.

Definition at line 196 of file test_notifications.py.

196 def test_modal_sd_without_greeter(self):
197 """Snap-decision should block input to shell
198 without greeter/lockscreen.
199 """
200 self.launch_lomiri()
201 unlock_lomiri()
202
203 summary = "Incoming file"
204 body = "Frank would like to send you the file: essay.pdf"
205 icon_path = "sync-idle"
206 hints = [
207 ("x-lomiri-snap-decisions", "true"),
208 ("x-lomiri-non-shaped-icon", "true"),
209 ("x-lomiri-private-affirmative-tint", "true"),
210 ("x-lomiri-private-rejection-tint", "true"),
211 ]
212
213 actions = [
214 ('action_accept', 'Accept'),
215 ('action_decline_1', 'Decline'),
216 ]
217
218 self._create_interactive_notification(
219 summary,
220 body,
221 icon_path,
222 "NORMAL",
223 actions,
224 hints
225 )
226
227 # verify that we cannot reveal the launcher (no longer interact with
228 # the shell)
229 time.sleep(1)
230 self.main_window.show_dash_swiping()
231 self.assertThat(
232 self.main_window.is_launcher_open, Eventually(Equals(False)))
233
234 # verify and interact with the triggered snap-decision notification
235 notify_list = self._get_notifications_list()
236 get_notification = lambda: notify_list.wait_select_single(
237 'Notification', objectName='notification0')
238 notification = get_notification()
239 self._assert_notification(
240 notification, summary, body, True, False, 1.0)
241 notification.pointing_device.click_object(
242 notification.select_single(objectName="notify_button0"))
243 self.assert_notification_action_id_was_called("action_accept")
244

◆ test_sd_one_over_two_layout()

lomiri.shell.tests.test_notifications.InteractiveNotificationBase.test_sd_one_over_two_layout (   self)
Snap-decision with three actions should use
   one-over two button layout.

Definition at line 155 of file test_notifications.py.

155 def test_sd_one_over_two_layout(self):
156 """Snap-decision with three actions should use
157 one-over two button layout.
158 """
159 self.launch_lomiri()
160 unlock_lomiri()
161
162 summary = "Theatre at Ferria Stadium"
163 body = "at Ferria Stadium in Bilbao, Spain\n07578545317"
164 hints = [
165 ("x-lomiri-snap-decisions", "true"),
166 ("x-lomiri-non-shaped-icon", "true"),
167 ("x-lomiri-private-affirmative-tint", "true")
168 ]
169
170 actions = [
171 ('action_accept', 'Ok'),
172 ('action_decline_1', 'Snooze'),
173 ('action_decline_2', 'View'),
174 ]
175
176 self._create_interactive_notification(
177 summary,
178 body,
179 None,
180 "NORMAL",
181 actions,
182 hints
183 )
184
185 # verify and interact with the triggered snap-decision notification
186 notify_list = self._get_notifications_list()
187 get_notification = lambda: notify_list.wait_select_single(
188 'Notification', objectName='notification0')
189 notification = get_notification()
190 self._assert_notification(
191 notification, summary, body, False, False, 1.0)
192 notification.pointing_device.click_object(
193 notification.select_single(objectName="notify_oot_button0"))
194 self.assert_notification_action_id_was_called("action_accept")
195

Member Data Documentation

◆ _notify_proc

lomiri.shell.tests.test_notifications.InteractiveNotificationBase._notify_proc
protected

Definition at line 118 of file test_notifications.py.

◆ _tidy_up_script_process

lomiri.shell.tests.test_notifications.InteractiveNotificationBase._tidy_up_script_process
protected

Definition at line 354 of file test_notifications.py.


The documentation for this class was generated from the following file: