| 1 |
# SPDX-License-Identifier: LGPL-2.1-or-later |
| 2 |
# |
| 3 |
# This file is formatted with Python Black |
| 4 |
|
| 5 |
import tests as xdp |
| 6 |
|
| 7 |
import pytest |
| 8 |
|
| 9 |
|
| 10 |
ACCOUNT_DATA = { |
| 11 |
"id": "test", |
| 12 |
"name": "Test Name", |
| 13 |
"image": "file:///image.png", |
| 14 |
} |
| 15 |
|
| 16 |
|
| 17 |
@pytest.fixture |
| 18 |
def required_templates(): |
| 19 |
return { |
| 20 |
"account": { |
| 21 |
"results": ACCOUNT_DATA, |
| 22 |
}, |
| 23 |
} |
| 24 |
|
| 25 |
|
| 26 |
class TestAccount: |
| 27 |
def set_permission(self, dbus_con, app_id, permission): |
| 28 |
perm_store_intf = xdp.get_permission_store_iface(dbus_con) |
| 29 |
perm_store_intf.SetPermission( |
| 30 |
"wallpaper", |
| 31 |
True, |
| 32 |
"wallpaper", |
| 33 |
app_id, |
| 34 |
[permission], |
| 35 |
) |
| 36 |
|
| 37 |
def test_version(self, portals, dbus_con): |
| 38 |
xdp.check_version(dbus_con, "Account", 1) |
| 39 |
|
| 40 |
def test_basic1(self, portals, dbus_con, app_id): |
| 41 |
account_intf = xdp.get_portal_iface(dbus_con, "Account") |
| 42 |
mock_intf = xdp.get_mock_iface(dbus_con) |
| 43 |
|
| 44 |
reason = "reason" |
| 45 |
|
| 46 |
request = xdp.Request(dbus_con, account_intf) |
| 47 |
options = { |
| 48 |
"reason": reason, |
| 49 |
} |
| 50 |
response = request.call( |
| 51 |
"GetUserInformation", |
| 52 |
window="", |
| 53 |
options=options, |
| 54 |
) |
| 55 |
|
| 56 |
assert response |
| 57 |
assert response.response == 0 |
| 58 |
assert response.results["id"] == ACCOUNT_DATA["id"] |
| 59 |
assert response.results["name"] == ACCOUNT_DATA["name"] |
| 60 |
assert response.results["image"] == ACCOUNT_DATA["image"] |
| 61 |
|
| 62 |
# Check the impl portal was called with the right args |
| 63 |
method_calls = mock_intf.GetMethodCalls("GetUserInformation") |
| 64 |
assert len(method_calls) > 0 |
| 65 |
_, args = method_calls[-1] |
| 66 |
assert args[1] == app_id |
| 67 |
assert args[2] == "" # window |
| 68 |
assert args[3]["reason"] == reason |
| 69 |
|
| 70 |
def test_reason(self, portals, dbus_con): |
| 71 |
account_intf = xdp.get_portal_iface(dbus_con, "Account") |
| 72 |
mock_intf = xdp.get_mock_iface(dbus_con) |
| 73 |
|
| 74 |
reason = """This reason is unreasonably long, it stretches over |
| 75 |
more than twohundredfiftysix characters, which is really quite |
| 76 |
long. Excessively so. The portal frontend will silently drop |
| 77 |
reasons of this magnitude. If you can't express your reasons |
| 78 |
concisely, you probably have no good reason in the first place |
| 79 |
and are just waffling around.""" |
| 80 |
|
| 81 |
assert len(reason) - 1 > 256 |
| 82 |
|
| 83 |
request = xdp.Request(dbus_con, account_intf) |
| 84 |
options = { |
| 85 |
"reason": reason, |
| 86 |
} |
| 87 |
response = request.call( |
| 88 |
"GetUserInformation", |
| 89 |
window="", |
| 90 |
options=options, |
| 91 |
) |
| 92 |
|
| 93 |
assert response |
| 94 |
assert response.response == 0 |
| 95 |
|
| 96 |
# Check the impl portal was called with the right args |
| 97 |
method_calls = mock_intf.GetMethodCalls("GetUserInformation") |
| 98 |
assert len(method_calls) > 0 |
| 99 |
_, args = method_calls[-1] |
| 100 |
assert "reason" not in args[3] |
| 101 |
|
| 102 |
@pytest.mark.parametrize("template_params", ({"account": {"expect-close": True}},)) |
| 103 |
def test_close(self, portals, dbus_con): |
| 104 |
account_intf = xdp.get_portal_iface(dbus_con, "Account") |
| 105 |
|
| 106 |
reason = "reason" |
| 107 |
|
| 108 |
request = xdp.Request(dbus_con, account_intf) |
| 109 |
request.schedule_close(1000) |
| 110 |
options = { |
| 111 |
"reason": reason, |
| 112 |
} |
| 113 |
request.call( |
| 114 |
"GetUserInformation", |
| 115 |
window="", |
| 116 |
options=options, |
| 117 |
) |
| 118 |
|
| 119 |
# Only true if the impl.Request was closed too |
| 120 |
assert request.closed |