def notify_user(self, message: Message) -> None: # Check if notifications are enabled by the user. # It is disabled by default. if not self.controller.notify_enabled: return if message['sender_id'] == self.user_id: return recipient = '' if message['type'] == 'private': target = 'you' if len(message['display_recipient']) > 2: extra_targets = [target] + [ recip['full_name'] for recip in message['display_recipient'] if recip['id'] not in (self.user_id, message['sender_id']) ] target = ', '.join(extra_targets) recipient = ' (to {})'.format(target) elif {'mentioned', 'wildcard_mentioned'}.intersection( set(message['flags'])) and message['type'] == 'stream': recipient = ' (to {} -> {})'.format(message['display_recipient'], message['subject']) if recipient: notify((self.server_name + ":\n" + message['sender_full_name'] + recipient), message['content'])
def test_notify(mocker, OS, is_notification_sent): title = "Author" text = "Hello!" mocker.patch('zulipterminal.helper.WSL', OS[0]) mocker.patch('zulipterminal.helper.MACOS', OS[1]) mocker.patch('zulipterminal.helper.LINUX', OS[2]) subprocess = mocker.patch('zulipterminal.helper.subprocess') notify(title, text) assert subprocess.run.called == is_notification_sent
def test_notify( mocker: MockerFixture, OS: List[bool], is_notification_sent: bool ) -> None: title = "Author" text = "Hello!" mocker.patch(MODULE + ".WSL", OS[0]) mocker.patch(MODULE + ".MACOS", OS[1]) mocker.patch(MODULE + ".LINUX", OS[2]) subprocess = mocker.patch(MODULE + ".subprocess") notify(title, text) assert subprocess.run.called == is_notification_sent
def test_notify_quotes(monkeypatch, mocker, OS, cmd_length, title, text): subprocess = mocker.patch('zulipterminal.helper.subprocess') for os in ('LINUX', 'MACOS', 'WSL'): if os != OS: monkeypatch.setattr(zulipterminal.helper, os, False) else: monkeypatch.setattr(zulipterminal.helper, os, True) notify(title, text) params = subprocess.run.call_args_list assert len(params) == 1 # One external run call assert len(params[0][0][0]) == cmd_length
def notify_user(self, message: Message) -> str: """ return value signifies if notification failed, if it should occur """ # Check if notifications are enabled by the user. # It is disabled by default. if not self.controller.notify_enabled: return "" if message['sender_id'] == self.user_id: return "" recipient = '' if message['type'] == 'private': target = 'you' if len(message['display_recipient']) > 2: extra_targets = [target] + [ recip['full_name'] for recip in message['display_recipient'] if recip['id'] not in (self.user_id, message['sender_id']) ] target = ', '.join(extra_targets) recipient = ' (to {})'.format(target) elif message['type'] == 'stream' and ({ 'mentioned', 'wildcard_mentioned' }.intersection(set(message['flags'])) or self.stream_dict[ message['stream_id']]['desktop_notifications']): recipient = ' (to {} -> {})'.format(message['display_recipient'], message['subject']) if recipient: return notify((self.server_name + ":\n" + message['sender_full_name'] + recipient), message['content']) return ""
def notify_user(self, message: Dict[str, Any]) -> None: # Check if notifications are enabled by the user. # It is disabled by default. if not self.controller.notify_enabled: return if message['sender_id'] == self.user_id: return recipient = '' if message['type'] == 'private': recipient = ' (to you)' elif {'mentioned', 'wildcard_mentioned'}.intersection( set(message['flags'])) and message['type'] == 'stream': recipient = ' (to {} -> {})'.format(message['display_recipient'], message['subject']) if recipient: notify(message['sender_full_name'] + recipient, message['content'])
def test_notify_quotes( monkeypatch: pytest.MonkeyPatch, mocker: MockerFixture, OS: str, cmd_length: int, title: str, text: str, ) -> None: subprocess = mocker.patch(MODULE + ".subprocess") for os in ("LINUX", "MACOS", "WSL"): if os != OS: monkeypatch.setattr(zulipterminal.helper, os, False) else: monkeypatch.setattr(zulipterminal.helper, os, True) notify(title, text) params = subprocess.run.call_args_list assert len(params) == 1 # One external run call assert len(params[0][0][0]) == cmd_length