871
872
self.assertEqual(output, expected_output)
872
873
def test_one_client(self):
873
output = PrintTableCmd().output({"foo": self.clients["foo"]})
874
output = PrintTableCmd().output({"foo": self.client})
874
875
expected_output = """
875
876
Name Enabled Timeout Last Successful Check
876
877
foo Yes 00:05:00 2019-02-03T00:00:00
934
935
json_data = json.loads(DumpJSONCmd().output(self.clients))
935
936
self.assertDictEqual(json_data, self.expected_json)
936
937
def test_one_client(self):
937
clients = {"foo": self.clients["foo"]}
938
clients = {"foo": self.client}
938
939
json_data = json.loads(DumpJSONCmd().output(clients))
939
940
expected_json = {"foo": self.expected_json["foo"]}
940
941
self.assertDictEqual(json_data, expected_json)
944
945
self.assertTrue(all(IsEnabledCmd().is_enabled(client)
945
946
for client in self.clients.values()))
946
947
def test_is_enabled_does_get_attribute(self):
947
client = self.clients["foo"]
948
self.assertTrue(IsEnabledCmd().is_enabled(client))
949
self.assertListEqual(client.calls,
948
self.assertTrue(IsEnabledCmd().is_enabled(self.client))
949
self.assertListEqual(self.client.calls,
951
951
("se.recompile.Mandos.Client",
953
953
"org.freedesktop.DBus.Properties"))])
954
954
def test_is_enabled_run_exits_successfully(self):
955
client = self.clients["foo"]
956
955
with self.assertRaises(SystemExit) as e:
957
IsEnabledCmd().run(None, [client])
956
IsEnabledCmd().run(None, [self.client])
958
957
if e.exception.code is not None:
959
958
self.assertEqual(e.exception.code, 0)
961
960
self.assertIsNone(e.exception.code)
962
961
def test_is_enabled_run_exits_with_failure(self):
963
client = self.clients["foo"]
964
client["Enabled"] = dbus.Boolean(False)
962
self.client["Enabled"] = dbus.Boolean(False)
965
963
with self.assertRaises(SystemExit) as e:
966
IsEnabledCmd().run(None, [client])
964
IsEnabledCmd().run(None, [self.client])
967
965
if isinstance(e.exception.code, int):
968
966
self.assertNotEqual(e.exception.code, 0)
973
971
class TestRemoveCmd(TestCmd):
974
972
def test_remove(self):
975
client = self.clients["foo"]
976
973
class MockMandos(object):
977
974
def __init__(self):
979
976
def RemoveClient(self, dbus_path):
980
977
self.calls.append(("RemoveClient", (dbus_path,)))
981
978
mandos = MockMandos()
982
RemoveCmd().run(mandos, [client])
979
RemoveCmd().run(mandos, [self.client])
983
980
self.assertEqual(len(mandos.calls), 1)
984
981
self.assertListEqual(mandos.calls,
985
982
[("RemoveClient",
986
(client.__dbus_object_path__,))])
983
(self.client.__dbus_object_path__,))])