support/testing: test_polkit.py: use assertRun{, Not}Ok()

Use the helpers to simplify the test.

Signed-off-by: Peter Korsgaard <peter@korsgaard.com>
This commit is contained in:
Peter Korsgaard
2026-06-18 14:48:13 +02:00
parent e5c017f663
commit a4ef71a592

View File

@@ -43,20 +43,16 @@ class TestPolkitSystemd(TestPolkitInfra):
rule_file = "systemd-timesyncd-restart.rules"
for rule_path in TestPolkitInfra.rule_paths:
cmd = "su brtest -c '/bin/systemctl restart systemd-timesyncd.service'"
_, exit_code = self.emulator.run(cmd, 10)
self.assertNotEqual(exit_code, 0)
self.assertRunNotOk(cmd, 10)
cmd = "cp /root/{file} {path}".format(file=rule_file, path=rule_path)
_, exit_code = self.emulator.run(cmd, 10)
self.assertEqual(exit_code, 0)
self.assertRunOk(cmd, 10)
cmd = "su brtest -c '/bin/systemctl restart systemd-timesyncd.service'"
_, exit_code = self.emulator.run(cmd, 10)
self.assertEqual(exit_code, 0)
self.assertRunOk(cmd, 10)
cmd = "rm {path}/{file}".format(file=rule_file, path=rule_path)
_, exit_code = self.emulator.run(cmd, 10)
self.assertEqual(exit_code, 0)
self.assertRunOk(cmd, 10)
class TestPolkitInitd(TestPolkitInfra):
@@ -73,8 +69,7 @@ class TestPolkitInitd(TestPolkitInfra):
self.assertEqual(output[0], "Error executing command as another user: Not authorized")
cmd = "cp /root/{file} {path}/{file}".format(file=rule_file, path=rule_path)
_, exit_code = self.emulator.run(cmd, 10)
self.assertEqual(exit_code, 0)
self.assertRunOk(cmd, 10)
cmd = "su brtest -c 'pkexec hello-polkit'"
output, exit_code = self.emulator.run(cmd, 10)
@@ -82,5 +77,4 @@ class TestPolkitInitd(TestPolkitInfra):
self.assertEqual(output[0], "Hello polkit!")
cmd = "rm {path}/{file}".format(file=rule_file, path=rule_path)
_, exit_code = self.emulator.run(cmd, 10)
self.assertEqual(exit_code, 0)
self.assertRunOk(cmd, 10)