795
795
self.calls.append(("Get", (interface, property,
796
796
dbus_interface)))
797
797
return self.attributes[property]
798
def Approve(self, approve, dbus_interface):
799
testcase.assertEqual(dbus_interface, client_interface)
800
self.calls.append(("Approve", (approve,
802
798
def __getitem__(self, key):
803
799
return self.attributes[key]
804
800
def __setitem__(self, key, value):
939
934
json_data = json.loads(DumpJSONCmd().output(self.clients))
940
935
self.assertDictEqual(json_data, self.expected_json)
941
936
def test_one_client(self):
942
clients = {"foo": self.client}
937
clients = {"foo": self.clients["foo"]}
943
938
json_data = json.loads(DumpJSONCmd().output(clients))
944
939
expected_json = {"foo": self.expected_json["foo"]}
945
940
self.assertDictEqual(json_data, expected_json)
949
944
self.assertTrue(all(IsEnabledCmd().is_enabled(client)
950
945
for client in self.clients.values()))
951
946
def test_is_enabled_does_get_attribute(self):
952
self.assertTrue(IsEnabledCmd().is_enabled(self.client))
953
self.assertListEqual(self.client.calls,
947
client = self.clients["foo"]
948
self.assertTrue(IsEnabledCmd().is_enabled(client))
949
self.assertListEqual(client.calls,
955
951
("se.recompile.Mandos.Client",
957
953
"org.freedesktop.DBus.Properties"))])
958
954
def test_is_enabled_run_exits_successfully(self):
955
client = self.clients["foo"]
959
956
with self.assertRaises(SystemExit) as e:
960
IsEnabledCmd().run(None, [self.client])
957
IsEnabledCmd().run_on_one_client(client)
961
958
if e.exception.code is not None:
962
959
self.assertEqual(e.exception.code, 0)
964
961
self.assertIsNone(e.exception.code)
965
962
def test_is_enabled_run_exits_with_failure(self):
966
self.client["Enabled"] = dbus.Boolean(False)
963
client = self.clients["foo"]
964
client["Enabled"] = dbus.Boolean(False)
967
965
with self.assertRaises(SystemExit) as e:
968
IsEnabledCmd().run(None, [self.client])
966
IsEnabledCmd().run_on_one_client(client)
969
967
if isinstance(e.exception.code, int):
970
968
self.assertNotEqual(e.exception.code, 0)
972
970
self.assertIsNotNone(e.exception.code)
974
class TestRemoveCmd(TestCmd):
975
def test_remove(self):
976
class MockMandos(object):
979
def RemoveClient(self, dbus_path):
980
self.calls.append(("RemoveClient", (dbus_path,)))
981
mandos = MockMandos()
982
RemoveCmd().run(mandos, [self.client])
983
self.assertEqual(len(mandos.calls), 1)
984
self.assertListEqual(mandos.calls,
986
(self.client.__dbus_object_path__,))])
988
class TestApproveCmd(TestCmd):
989
def test_approve(self):
990
ApproveCmd().run(None, [self.client])
991
self.assertListEqual(self.client.calls,
992
[("Approve", (True, client_interface))])
993
class TestDenyCmd(TestCmd):
994
def test_approve(self):
995
DenyCmd().run(None, [self.client])
996
self.assertListEqual(self.client.calls,
997
[("Approve", (False, client_interface))])
1001
974
def should_only_run_tests():