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

## 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 = None
| _tidy_up_script_process
Protected Attributes inherited from lomiri.shell.tests.LomiriTestCase
| _proxy = None
bool | _qml_mock_enabled = True
bool | _data_dirs_mock_enabled = True
dict | _environment = {}
| _clear_proxy

## Additional Inherited Members

Public Attributes inherited from lomiri.shell.tests.LomiriTestCase
list | lomiri_geometry_args = []
int | grid_size = 8
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.

):
"""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
"""
logger.info(
"Creating snap-decision notification with summary(%s), body(%s) "
"and urgency(%r)",
summary,
body,
urgency
)
script_args = [
'--summary', summary,
'--body', body,
'--urgency', urgency
]
if icon is not None:
script_args.extend(['--icon', icon])
for hint in hints:
key, value = hint
script_args.extend(['--hint', "%s,%s" % (key, value)])
for action in actions:
action_id, action_label = action
action_string = "%s,%s" % (action_id, action_label)
script_args.extend(['--action', action_string])
python_bin = subprocess.check_output(['which', 'python3']).strip()
command = [python_bin, self._get_notify_script()] + script_args
logger.info("Launching snap-decision notification as: %s", command)
self._notify_proc = subprocess.Popen(
command,
stdin=subprocess.PIPE,
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
close_fds=True,
universal_newlines=True,
)
self.addCleanup(self._tidy_up_script_process)
poll_result = self._notify_proc.poll()
if poll_result is not None and self._notify_proc.returncode != 0:
error_output = self._notify_proc.communicate()[1]
raise RuntimeError("Call to script failed with: %s" % error_output)

## _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.

def _get_notify_script(self):
"""Returns the path to the interactive notification
creation script.
"""
file_path = "../../create_interactive_notification.py"
the_path = os.path.abspath(
os.path.join(__file__, file_path))
return the_path

## _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.

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

## 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.

def 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.
"""
if self._notify_proc is None:
raise AssertionError("No interactive notification was created.")
for i in range(timeout):
self._notify_proc.poll()
if self._notify_proc.returncode is not None:
output = self._notify_proc.communicate()
actual_action_id = output[0].strip("\n")
if actual_action_id != action_id:
raise AssertionError(
"action id '%s' does not match actual returned '%s'"
% (action_id, actual_action_id)
)
else:
return
time.sleep(1)
os.killpg(self._notify_proc.pid, signal.SIGTERM)
self._notify_proc = None
raise AssertionError(
"No callback was called, killing interactivenotification script"
)

## setUp()

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

Reimplemented from lomiri.shell.tests.LomiriTestCase.

Definition at line 115 of file test_notifications.py.

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

## 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.

def test_interactive(self):
"""Interactive notification must react upon click on itself."""
self.launch_lomiri()
unlock_lomiri()
notify_list = self._get_notifications_list()
summary = "Interactive notification"
body = "This notification can be clicked on to trigger an action."
icon_path = self._get_icon_path('avatars/anna_olsson.png')
actions = [("action_id", "dummy")]
hints = [
("x-lomiri-switch-to-application", "true"),
("x-lomiri-secondary-icon", "dialer")
]
self._create_interactive_notification(
summary,
body,
icon_path,
"NORMAL",
actions,
hints,
)
get_notification = lambda: notify_list.wait_select_single(
'Notification', objectName='notification0')
notification = get_notification()
notification.pointing_device.click_object(
notification.select_single(objectName="interactiveArea")
)
self.assert_notification_action_id_was_called('action_id')

## 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.

def test_modal_sd_with_greeter(self):
"""A snap-decision should block input to the
greeter/lockscreen beneath it.
"""
self.launch_lomiri()
summary = "Incoming file"
body = "Frank would like to send you the file: essay.pdf"
icon_path = "sync-idle"
hints = [
("x-lomiri-snap-decisions", "true"),
("x-lomiri-non-shaped-icon", "true"),
("x-lomiri-private-affirmative-tint", "true"),
("x-lomiri-private-rejection-tint", "true"),
]
actions = [
('action_accept', 'Accept'),
('action_decline_1', 'Decline'),
]
self._create_interactive_notification(
summary,
body,
icon_path,
"NORMAL",
actions,
hints
)
# verify that we cannot reveal the launcher (no longer interact with
# the shell)
time.sleep(1)
self.main_window.show_dash_swiping()
self.assertThat(
self.main_window.is_launcher_open, Eventually(Equals(False)))
# verify and interact with the triggered snap-decision notification
notify_list = self._get_notifications_list()
get_notification = lambda: notify_list.wait_select_single(
'Notification', objectName='notification0')
notification = get_notification()
self._assert_notification(
notification, summary, body, True, False, 1.0)
notification.pointing_device.click_object(
notification.select_single(objectName="notify_button0"))
self.assert_notification_action_id_was_called("action_accept")

## 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.

def test_modal_sd_without_greeter(self):
"""Snap-decision should block input to shell
without greeter/lockscreen.
"""
self.launch_lomiri()
unlock_lomiri()
summary = "Incoming file"
body = "Frank would like to send you the file: essay.pdf"
icon_path = "sync-idle"
hints = [
("x-lomiri-snap-decisions", "true"),
("x-lomiri-non-shaped-icon", "true"),
("x-lomiri-private-affirmative-tint", "true"),
("x-lomiri-private-rejection-tint", "true"),
]
actions = [
('action_accept', 'Accept'),
('action_decline_1', 'Decline'),
]
self._create_interactive_notification(
summary,
body,
icon_path,
"NORMAL",
actions,
hints
)
# verify that we cannot reveal the launcher (no longer interact with
# the shell)
time.sleep(1)
self.main_window.show_dash_swiping()
self.assertThat(
self.main_window.is_launcher_open, Eventually(Equals(False)))
# verify and interact with the triggered snap-decision notification
notify_list = self._get_notifications_list()
get_notification = lambda: notify_list.wait_select_single(
'Notification', objectName='notification0')
notification = get_notification()
self._assert_notification(
notification, summary, body, True, False, 1.0)
notification.pointing_device.click_object(
notification.select_single(objectName="notify_button0"))
self.assert_notification_action_id_was_called("action_accept")

## 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.

def test_sd_one_over_two_layout(self):
"""Snap-decision with three actions should use
one-over two button layout.
"""
self.launch_lomiri()
unlock_lomiri()
summary = "Theatre at Ferria Stadium"
body = "at Ferria Stadium in Bilbao, Spain\n07578545317"
hints = [
("x-lomiri-snap-decisions", "true"),
("x-lomiri-non-shaped-icon", "true"),
("x-lomiri-private-affirmative-tint", "true")
]
actions = [
('action_accept', 'Ok'),
('action_decline_1', 'Snooze'),
('action_decline_2', 'View'),
]
self._create_interactive_notification(
summary,
body,
None,
"NORMAL",
actions,
hints
)
# verify and interact with the triggered snap-decision notification
notify_list = self._get_notifications_list()
get_notification = lambda: notify_list.wait_select_single(
'Notification', objectName='notification0')
notification = get_notification()
self._assert_notification(
notification, summary, body, False, False, 1.0)
notification.pointing_device.click_object(
notification.select_single(objectName="notify_oot_button0"))
self.assert_notification_action_id_was_called("action_accept")

## Member Data Documentation

## _notify_proc

lomiri.shell.tests.test_notifications.InteractiveNotificationBase._notify_proc = None

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:

- tests/autopilot/lomiri/shell/tests/test_notifications.py