Skip to content

Commit

Permalink
tests/notification: Add a pytest variant
Browse files Browse the repository at this point in the history
  • Loading branch information
swick committed Jan 7, 2025
1 parent 517a0a4 commit 28a0620
Show file tree
Hide file tree
Showing 3 changed files with 605 additions and 0 deletions.
1 change: 1 addition & 0 deletions tests/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,7 @@ if enable_pytest
'test_inhibit.py',
'test_inputcapture.py',
'test_location.py',
'test_notification.py',
'test_openuri.py',
'test_print.py',
'test_remotedesktop.py',
Expand Down
81 changes: 81 additions & 0 deletions tests/templates/notification.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# SPDX-License-Identifier: LGPL-2.1-or-later
#
# This file is formatted with Python Black

from tests.templates import init_template_logger

import dbus.service
from dbusmock import MOCK_IFACE


BUS_NAME = "org.freedesktop.impl.portal.Test"
MAIN_OBJ = "/org/freedesktop/portal/desktop"
SYSTEM_BUS = False
MAIN_IFACE = "org.freedesktop.impl.portal.Notification"
VERSION = 2


logger = init_template_logger(__name__)


def load(mock, parameters={}):
logger.debug(f"Loading parameters: {parameters}")

mock.AddProperties(
MAIN_IFACE,
dbus.Dictionary(
{
"version": dbus.UInt32(parameters.get("version", VERSION)),
"SupportedOptions": dbus.Dictionary(
parameters.get("SupportedOptions", {}), signature="sv"
),
},
),
)
mock.notifications = {}


@dbus.service.method(
MAIN_IFACE,
in_signature="ssa{sv}",
out_signature="",
)
def AddNotification(self, app_id, id, notification):
logger.debug(f"AddNotification({app_id}, {id}, {notification})")

self.notifications.setdefault(app_id, {})[id] = notification


@dbus.service.method(
MAIN_IFACE,
in_signature="ss",
out_signature="",
)
def RemoveNotification(self, app_id, id):
logger.debug(f"AddNotification({app_id}, {id})")

del self.notifications[app_id][id]


@dbus.service.method(
MOCK_IFACE,
in_signature="sssav",
out_signature="",
)
def EmitActionInvoked(self, app_id, id, action, parameter):
logger.debug(f"EmitActionInvoked({app_id}, {id}, {action}, {parameter})")

# n = self.notifications[app_id][id]
# FIXME check action is in n

self.EmitSignal(
MAIN_IFACE,
"ActionInvoked",
"sssav",
[
app_id,
id,
action,
dbus.Array(parameter, signature="v"),
],
)
Loading

0 comments on commit 28a0620

Please sign in to comment.