1108
1108
class Test_get_managed_objects(TestCaseWithAssertLogs):
1109
1109
def test_calls_and_returns_GetManagedObjects(self):
1110
managed_objects = {"/clients/foo": { "Name": "foo"}}
1111
class MockObjectManager(object):
1110
managed_objects = {"/clients/client": { "Name": "client"}}
1111
class ObjectManagerStub(object):
1112
1112
def GetManagedObjects(self):
1113
1113
return managed_objects
1114
retval = get_managed_objects(MockObjectManager())
1114
retval = get_managed_objects(ObjectManagerStub())
1115
1115
self.assertDictEqual(managed_objects, retval)
1117
1117
def test_logs_and_exits_on_dbus_error(self):
1118
1118
dbus_logger = logging.getLogger("dbus.proxies")
1120
class MockObjectManagerFailing(object):
1120
class ObjectManagerFailingStub(object):
1121
1121
def GetManagedObjects(self):
1122
1122
dbus_logger.error("Test")
1123
1123
raise dbus.exceptions.DBusException("Test")
1174
1174
self.assertEqual(value, getattr(command, key))
1176
1176
def test_is_enabled_short(self):
1177
self.assert_command_from_args(["-V", "foo"],
1177
self.assert_command_from_args(["-V", "client"],
1178
1178
command.IsEnabled)
1180
1180
def test_approve(self):
1181
self.assert_command_from_args(["--approve", "foo"],
1181
self.assert_command_from_args(["--approve", "client"],
1182
1182
command.Approve)
1184
1184
def test_approve_short(self):
1185
self.assert_command_from_args(["-A", "foo"], command.Approve)
1185
self.assert_command_from_args(["-A", "client"],
1187
1188
def test_deny(self):
1188
self.assert_command_from_args(["--deny", "foo"], command.Deny)
1189
self.assert_command_from_args(["--deny", "client"],
1190
1192
def test_deny_short(self):
1191
self.assert_command_from_args(["-D", "foo"], command.Deny)
1193
self.assert_command_from_args(["-D", "client"], command.Deny)
1193
1195
def test_remove(self):
1194
self.assert_command_from_args(["--remove", "foo"],
1196
self.assert_command_from_args(["--remove", "client"],
1195
1197
command.Remove)
1197
1199
def test_deny_before_remove(self):
1198
1200
options = self.parser.parse_args(["--deny", "--remove",
1200
1202
check_option_syntax(self.parser, options)
1201
1203
commands = commands_from_options(options)
1202
1204
self.assertEqual(2, len(commands))
1213
1215
self.assertIsInstance(commands[1], command.Remove)
1215
1217
def test_remove_short(self):
1216
self.assert_command_from_args(["-r", "foo"], command.Remove)
1218
self.assert_command_from_args(["-r", "client"],
1218
1221
def test_dump_json(self):
1219
1222
self.assert_command_from_args(["--dump-json"],
1220
1223
command.DumpJSON)
1222
1225
def test_enable(self):
1223
self.assert_command_from_args(["--enable", "foo"],
1226
self.assert_command_from_args(["--enable", "client"],
1224
1227
command.Enable)
1226
1229
def test_enable_short(self):
1227
self.assert_command_from_args(["-e", "foo"], command.Enable)
1230
self.assert_command_from_args(["-e", "client"],
1229
1233
def test_disable(self):
1230
self.assert_command_from_args(["--disable", "foo"],
1234
self.assert_command_from_args(["--disable", "client"],
1231
1235
command.Disable)
1233
1237
def test_disable_short(self):
1234
self.assert_command_from_args(["-d", "foo"], command.Disable)
1238
self.assert_command_from_args(["-d", "client"],
1236
1241
def test_bump_timeout(self):
1237
self.assert_command_from_args(["--bump-timeout", "foo"],
1242
self.assert_command_from_args(["--bump-timeout", "client"],
1238
1243
command.BumpTimeout)
1240
1245
def test_bump_timeout_short(self):
1241
self.assert_command_from_args(["-b", "foo"],
1246
self.assert_command_from_args(["-b", "client"],
1242
1247
command.BumpTimeout)
1244
1249
def test_start_checker(self):
1245
self.assert_command_from_args(["--start-checker", "foo"],
1250
self.assert_command_from_args(["--start-checker", "client"],
1246
1251
command.StartChecker)
1248
1253
def test_stop_checker(self):
1249
self.assert_command_from_args(["--stop-checker", "foo"],
1254
self.assert_command_from_args(["--stop-checker", "client"],
1250
1255
command.StopChecker)
1252
1257
def test_approve_by_default(self):
1253
self.assert_command_from_args(["--approve-by-default", "foo"],
1258
self.assert_command_from_args(["--approve-by-default",
1254
1260
command.ApproveByDefault)
1256
1262
def test_deny_by_default(self):
1257
self.assert_command_from_args(["--deny-by-default", "foo"],
1263
self.assert_command_from_args(["--deny-by-default", "client"],
1258
1264
command.DenyByDefault)
1260
1266
def test_checker(self):
1261
self.assert_command_from_args(["--checker", ":", "foo"],
1267
self.assert_command_from_args(["--checker", ":", "client"],
1262
1268
command.SetChecker,
1263
1269
value_to_set=":")
1265
1271
def test_checker_empty(self):
1266
self.assert_command_from_args(["--checker", "", "foo"],
1272
self.assert_command_from_args(["--checker", "", "client"],
1267
1273
command.SetChecker,
1268
1274
value_to_set="")
1270
1276
def test_checker_short(self):
1271
self.assert_command_from_args(["-c", ":", "foo"],
1277
self.assert_command_from_args(["-c", ":", "client"],
1272
1278
command.SetChecker,
1273
1279
value_to_set=":")
1275
1281
def test_host(self):
1276
self.assert_command_from_args(["--host", "foo.example.org",
1277
"foo"], command.SetHost,
1278
value_to_set="foo.example.org")
1282
self.assert_command_from_args(
1283
["--host", "client.example.org", "client"],
1284
command.SetHost, value_to_set="client.example.org")
1280
1286
def test_host_short(self):
1281
self.assert_command_from_args(["-H", "foo.example.org",
1282
"foo"], command.SetHost,
1283
value_to_set="foo.example.org")
1287
self.assert_command_from_args(
1288
["-H", "client.example.org", "client"], command.SetHost,
1289
value_to_set="client.example.org")
1285
1291
def test_secret_devnull(self):
1286
1292
self.assert_command_from_args(["--secret", os.path.devnull,
1287
"foo"], command.SetSecret,
1293
"client"], command.SetSecret,
1288
1294
value_to_set=b"")
1290
1296
def test_secret_tempfile(self):
1306
1313
value = b"secret\0xyzzy\nbar"
1309
self.assert_command_from_args(["-s", f.name, "foo"],
1316
self.assert_command_from_args(["-s", f.name, "client"],
1310
1317
command.SetSecret,
1311
1318
value_to_set=value)
1313
1320
def test_timeout(self):
1314
self.assert_command_from_args(["--timeout", "PT5M", "foo"],
1321
self.assert_command_from_args(["--timeout", "PT5M", "client"],
1315
1322
command.SetTimeout,
1316
1323
value_to_set=300000)
1318
1325
def test_timeout_short(self):
1319
self.assert_command_from_args(["-t", "PT5M", "foo"],
1326
self.assert_command_from_args(["-t", "PT5M", "client"],
1320
1327
command.SetTimeout,
1321
1328
value_to_set=300000)
1323
1330
def test_extended_timeout(self):
1324
1331
self.assert_command_from_args(["--extended-timeout", "PT15M",
1326
1333
command.SetExtendedTimeout,
1327
1334
value_to_set=900000)
1329
1336
def test_interval(self):
1330
self.assert_command_from_args(["--interval", "PT2M", "foo"],
1331
command.SetInterval,
1337
self.assert_command_from_args(["--interval", "PT2M",
1338
"client"], command.SetInterval,
1332
1339
value_to_set=120000)
1334
1341
def test_interval_short(self):
1335
self.assert_command_from_args(["-i", "PT2M", "foo"],
1342
self.assert_command_from_args(["-i", "PT2M", "client"],
1336
1343
command.SetInterval,
1337
1344
value_to_set=120000)
1339
1346
def test_approval_delay(self):
1340
1347
self.assert_command_from_args(["--approval-delay", "PT30S",
1342
1349
command.SetApprovalDelay,
1343
1350
value_to_set=30000)
1345
1352
def test_approval_duration(self):
1346
1353
self.assert_command_from_args(["--approval-duration", "PT1S",
1348
1355
command.SetApprovalDuration,
1349
1356
value_to_set=1000)
1433
1440
LastCheckerStatus=-2)
1434
1441
self.clients = collections.OrderedDict(
1436
("/clients/foo", self.client.attributes),
1437
("/clients/barbar", self.other_client.attributes),
1443
(self.client.__dbus_object_path__,
1444
self.client.attributes),
1445
(self.other_client.__dbus_object_path__,
1446
self.other_client.attributes),
1439
self.one_client = {"/clients/foo": self.client.attributes}
1448
self.one_client = {self.client.__dbus_object_path__:
1449
self.client.attributes}
1453
class MockBus(object):
1445
1455
def get_object(client_bus_name, path):
1446
1456
self.assertEqual(dbus_busname, client_bus_name)
1448
# Note: "self" here is the TestCmd instance, not
1449
# the Bus instance, since this is a static method!
1450
"/clients/foo": self.client,
1451
"/clients/barbar": self.other_client,
1457
# Note: "self" here is the TestCmd instance, not the
1458
# MockBus instance, since this is a static method!
1459
if path == self.client.__dbus_object_path__:
1461
elif path == self.other_client.__dbus_object_path__:
1462
return self.other_client
1456
1466
class TestBaseCommands(TestCommand):