Add test for filtering

This commit is contained in:
Kovid Goyal 2024-07-28 09:15:18 +05:30
parent 67410c317f
commit 59c175f312
No known key found for this signature in database
GPG key ID: 06BC317B515ACE7C
2 changed files with 18 additions and 1 deletions

View file

@ -685,11 +685,15 @@ def is_notification_allowed(self, cmd: NotificationCommand, channel_id: int, app
return False
return True
@property
def filter_rules(self) -> Iterator[str]:
return iter(get_options().filter_notification.keys())
def is_notification_filtered(self, cmd: NotificationCommand) -> bool:
if self.filter_script(cmd):
self.log(f'Notification {cmd.title!r} filtered out by script')
return True
for rule in get_options().filter_notification:
for rule in self.filter_rules:
if cmd.matches_rule(rule):
self.log(f'Notification {cmd.title!r} filtered out by filter_notification rule: {rule}')
return True

View file

@ -69,6 +69,13 @@ def send(self, channel_id: int, osc_escape_code: str) -> bool:
self.responses.append(osc_escape_code)
class NotificationManager(NotificationManager):
@property
def filter_rules(self):
yield from ('title:filterme',)
def do_test(self: 'TestNotifications', tdir: str) -> None:
di = DesktopIntegration(None)
ch = Channel()
@ -162,6 +169,12 @@ def assert_events(focus=True, close=0, report='', close_response=''):
self.ae(di.notifications, [n()])
reset()
# test filtering
h(';title')
h(';filterme please')
self.ae(di.notifications, [n()])
reset()
# test closing interactions with reporting and activation
h('i=c;title')
self.ae(di.notifications, [n()])