def test_apple_notifier_escaping(): evil_notification = notifier.Notification('title "', 'subtitle "', 'message "') with MOCK_APPLE as check_output: notifier.AppleNotifier().send(evil_notification) assert check_output.call_args[0][0][2] == ( 'display notification "message \\"" ' 'with title "title \\"" subtitle "subtitle \\""')
def test_dbus_notifier_escaping(): evil_notification = notifier.Notification('<b>title</b> \\ \' "', None, '<b>message</b> \\ \' "') with MOCK_DBUS as check_output: notifier.DbusNotifier().send(evil_notification) assert check_output.call_args[0][0][12:14] == [ '<b>title</b> \\\\ \\u0027 \\u0022', '<b>message</b> \\\\ \\u0027 \\u0022', ]
def _on_event(self, conv_event): """Open conversation tab for new messages & pass events to notifier.""" conv = self._conv_list.get(conv_event.conversation_id) user = conv.get_user(conv_event.user_id) show_notification = all(( isinstance(conv_event, hangups.ChatMessageEvent), not user.is_self, not conv.is_quiet, )) if show_notification: self.add_conversation_tab(conv_event.conversation_id) if self._discreet_notifications: notification = DISCREET_NOTIFICATION else: notification = notifier.Notification( user.full_name, get_conv_name(conv), conv_event.text ) self._notifier.send(notification)
('msg_sender', 'dark blue', ''), ('msg_text_self', '', ''), ('msg_self', 'dark green', ''), ('msg_text', '', ''), ('msg_selected', 'standout', ''), ('status_line', 'standout', ''), ('tab_background', 'black,standout,underline', 'light green'), }, } COL_SCHEME_NAMES = ( 'active_tab', 'inactive_tab', 'msg_date', 'msg_sender', 'msg_self', 'msg_text', 'msg_text_self', 'status_line', 'tab_background' ) DISCREET_NOTIFICATION = notifier.Notification( 'hangups', 'Conversation', 'New message' ) class HangupsDisconnected(Exception): """Raised when hangups is disconnected.""" class ChatUI(object): """User interface for hangups.""" def __init__(self, refresh_token_path, keybindings, palette, palette_colors, datetimefmt, notifier_, discreet_notifications): """Start the user interface.""" self._keys = keybindings
import subprocess import unittest.mock from hangups.ui import notifier NOTIFICATION = notifier.Notification('John Cleese', 'Cheese Shop', 'How about a little red Leicester?') MOCK_DBUS = unittest.mock.patch('subprocess.check_output', autospec=True, return_value=b'(uint32 7,)\n') MOCK_APPLE = unittest.mock.patch('subprocess.check_output', autospec=True, return_value=b'') def test_bell_notifier(capsys): notifier.BellNotifier().send(NOTIFICATION) assert capsys.readouterr() == ('\a', '') def test_dbus_notifier(): with MOCK_DBUS as check_output: notifier.DbusNotifier().send(NOTIFICATION) check_output.assert_called_once_with([ 'gdbus', 'call', '--session', '--dest', 'org.freedesktop.Notifications', '--object-path', '/org/freedesktop/Notifications', '--method', 'org.freedesktop.Notifications.Notify', 'hangups', '0', '', 'John Cleese', 'How about a little red Leicester?', '[]', '{}', ' -1' ], stderr=subprocess.STDOUT)