Skip to content

Commit

Permalink
tests: Pass app Id to ImplSession
Browse files Browse the repository at this point in the history
This will eventually be used to check what app ID a portal sent to the
backend.
  • Loading branch information
jadahl authored and swick committed Jan 14, 2025
1 parent 95d5c12 commit e2b5648
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 9 deletions.
19 changes: 13 additions & 6 deletions tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,18 +91,23 @@ def get_mock_iface(bus: dbus.Bus, bus_name: Optional[str] = None):
return dbus.Interface(obj, dbusmock.MOCK_IFACE)


def portal_interface_name(portal_name) -> str:
def portal_interface_name(portal_name, domain: Optional[str] = None) -> str:
"""
Returns the fully qualified interface for a portal name.
"""
return f"org.freedesktop.portal.{portal_name}"
if domain:
return f"org.freedesktop.{domain}.portal.{portal_name}"
else:
return f"org.freedesktop.portal.{portal_name}"


def get_portal_iface(bus: dbus.Bus, name: str) -> dbus.Interface:
def get_portal_iface(
bus: dbus.Bus, name: str, domain: Optional[str] = None
) -> dbus.Interface:
"""
Returns the dbus interface for a portal name.
"""
name = portal_interface_name(name)
name = portal_interface_name(name, domain)
return get_iface(bus, name)


Expand Down Expand Up @@ -139,14 +144,16 @@ def get_xdp_dbus_object(bus: dbus.Bus) -> dbus.proxies.ProxyObject:
return obj


def check_version(bus: dbus.Bus, portal_name: str, expected_version: int):
def check_version(
bus: dbus.Bus, portal_name: str, expected_version: int, domain: Optional[str] = None
):
"""
Checks that the portal_name portal version is equal to expected_version.
"""
properties_intf = dbus.Interface(
get_xdp_dbus_object(bus), "org.freedesktop.DBus.Properties"
)
portal_iface_name = portal_interface_name(portal_name)
portal_iface_name = portal_interface_name(portal_name, domain)
try:
portal_version = properties_intf.Get(portal_iface_name, "version")
assert int(portal_version) == expected_version
Expand Down
2 changes: 2 additions & 0 deletions tests/templates/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,11 @@ def __init__(
mock: dbusmock.DBusMockObject,
busname: str,
handle: str,
app_id: str,
):
self.mock = mock # the main mock object
self.handle = handle
self.app_id = app_id
self.closed = False
self._close_callback: Optional[Callable] = None

Expand Down
2 changes: 1 addition & 1 deletion tests/templates/globalshortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def CreateSession(self, handle, session_handle, app_id, options, cb_success, cb_
try:
logger.debug(f"CreateSession({handle}, {session_handle}, {app_id}, {options})")

session = ImplSession(self, BUS_NAME, session_handle).export()
session = ImplSession(self, BUS_NAME, session_handle, app_id).export()
self.sessions[session_handle] = session

response = Response(self.response, {"session_handle": session.handle})
Expand Down
2 changes: 1 addition & 1 deletion tests/templates/inhibit.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ def CreateMonitor(self, handle, session_handle, app_id, window, cb_success, cb_e
try:
logger.debug(f"CreateMonitor({handle}, {session_handle}, {app_id}, {window})")

session = ImplSession(self, BUS_NAME, session_handle).export()
session = ImplSession(self, BUS_NAME, session_handle, app_id).export()
self.sessions[session_handle] = session

def closed_callback():
Expand Down
2 changes: 1 addition & 1 deletion tests/templates/remotedesktop.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def CreateSession(self, handle, session_handle, app_id, options, cb_success, cb_
try:
logger.debug(f"CreateSession({handle}, {session_handle}, {app_id}, {options})")

session = ImplSession(self, BUS_NAME, session_handle).export()
session = ImplSession(self, BUS_NAME, session_handle, app_id).export()
self.sessions[session_handle] = session

response = Response(self.response, {"session_handle": session.handle})
Expand Down

0 comments on commit e2b5648

Please sign in to comment.