Skip to content

Commit

Permalink
tests: Force a default app id for python tests
Browse files Browse the repository at this point in the history
Instead of querying x-d-p about the app id, we force the app id that
x-d-p uses for all client connections.

The `app_id` fixture and PortalMock allow to override this value. The
`app_id` fixture can be used in tests to access the app_id that x-d-p
will see.
  • Loading branch information
swick committed Mar 19, 2024
1 parent 593b600 commit f891634
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 7 deletions.
4 changes: 3 additions & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -332,13 +332,14 @@ class PortalMock:
Parent class for portal tests.
"""

def __init__(self, session_bus, portal_name: str):
def __init__(self, session_bus, portal_name: str, app_id: str = "org.example.App"):
self.bus = session_bus
self.portal_name = portal_name
self.p_mock = None
self.xdp = None
self.portal_interfaces: Dict[str, dbus.Interface] = {}
self.dbus_monitor = None
self.app_id = app_id

@property
def interface_name(self) -> str:
Expand Down Expand Up @@ -412,6 +413,7 @@ def start_xdp(self):
env["G_DEBUG"] = "fatal-criticals"
env["XDG_DESKTOP_PORTAL_DIR"] = portal_dir
env["XDG_CURRENT_DESKTOP"] = "test"
env["XDG_DESKTOP_PORTAL_TEST_APP_ID"] = self.app_id

xdp = subprocess.Popen(argv, env=env)

Expand Down
12 changes: 10 additions & 2 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,19 @@ def params() -> dict[str, Any]:


@pytest.fixture
def portal_mock(session_bus, portal_name, params, portal_has_impl) -> PortalMock:
def app_id():
"""
Default fixture providing the app id of the connecting process
"""
return "org.example.App"


@pytest.fixture
def portal_mock(session_bus, portal_name, params, portal_has_impl, app_id) -> PortalMock:
"""
Fixture yielding a PortalMock object with the impl started, if applicable.
"""
pmock = PortalMock(session_bus, portal_name)
pmock = PortalMock(session_bus, portal_name, app_id)
if portal_has_impl:
pmock.start_impl_portal(params)
pmock.start_xdp()
Expand Down
8 changes: 4 additions & 4 deletions tests/test_globalshortcuts.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class TestGlobalShortcuts:
def test_version(self, portal_mock):
portal_mock.check_version(1)

def test_global_shortcuts_create_close_session(self, portal_mock):
def test_global_shortcuts_create_close_session(self, portal_mock, app_id):
request = portal_mock.create_request()
options = {
"session_handle_token": "session_token0",
Expand All @@ -38,7 +38,7 @@ def test_global_shortcuts_create_close_session(self, portal_mock):
assert len(method_calls) > 0
_, args = method_calls[-1]
assert args[1] == session.handle
# assert args[2] == "" # appid, not necessary empty
assert args[2] == app_id

session.close()

Expand All @@ -49,7 +49,7 @@ def test_global_shortcuts_create_close_session(self, portal_mock):
assert session.closed

@pytest.mark.parametrize("params", ({"force-close": 500},))
def test_global_shortcuts_create_session_signal_closed(self, portal_mock):
def test_global_shortcuts_create_session_signal_closed(self, portal_mock, app_id):
request = portal_mock.create_request()
options = {
"session_handle_token": "session_token0",
Expand All @@ -67,7 +67,7 @@ def test_global_shortcuts_create_session_signal_closed(self, portal_mock):
assert len(method_calls) > 0
_, args = method_calls[-1]
assert args[1] == session.handle
# assert args[2] == "" # appid, not necessary empty
assert args[2] == app_id

# Now expect the backend to close it

Expand Down

0 comments on commit f891634

Please sign in to comment.