/mandos/trunk

To get this branch, use:
bzr branch http://bzr.recompile.se/loggerhead/mandos/trunk

« back to all changes in this revision

Viewing changes to mandos-ctl

  • Committer: Teddy Hogeborn
  • Date: 2019-03-17 16:54:02 UTC
  • Revision ID: teddy@recompile.se-20190317165402-g3ljjeea05p5ouvt
mandos-ctl: Refactor tests

* mandos-ctl (TestBaseCommands.test_IsEnabled): Removed; don't test
                                                internal details of
                                                command.IsEnabled.
  (TestBaseCommands.test_IsEnabled_run_exits_successfully): Rename to
                                  "test_IsEnabled_exits_successfully".
  (TestBaseCommands.test_IsEnabled_run_exits_with_failure): Rename to
                                  "test_IsEnabled_exits_with_failure".

Show diffs side-by-side

added added

removed removed

Lines of Context:
886
886
 
887
887
 
888
888
class Test_string_to_delta(TestCaseWithAssertLogs):
889
 
    def test_handles_basic_rfc3339(self):
 
889
    # Just test basic RFC 3339 functionality here, the doc string for
 
890
    # rfc3339_duration_to_delta() already has more comprehensive
 
891
    # tests, which is run by doctest.
 
892
 
 
893
    def test_rfc3339_zero_seconds(self):
890
894
        self.assertEqual(string_to_delta("PT0S"),
891
895
                         datetime.timedelta())
 
896
 
 
897
    def test_rfc3339_zero_days(self):
892
898
        self.assertEqual(string_to_delta("P0D"),
893
899
                         datetime.timedelta())
 
900
 
 
901
    def test_rfc3339_one_second(self):
894
902
        self.assertEqual(string_to_delta("PT1S"),
895
903
                         datetime.timedelta(0, 1))
 
904
 
 
905
    def test_rfc3339_two_hours(self):
896
906
        self.assertEqual(string_to_delta("PT2H"),
897
907
                         datetime.timedelta(0, 7200))
898
908
 
1376
1386
                testcase.assertEqual(dbus_interface,
1377
1387
                                     dbus.PROPERTIES_IFACE)
1378
1388
                self.attributes[propname] = value
1379
 
            def Get(self, interface, propname, dbus_interface):
1380
 
                testcase.assertEqual(interface, client_dbus_interface)
1381
 
                testcase.assertEqual(dbus_interface,
1382
 
                                     dbus.PROPERTIES_IFACE)
1383
 
                return self.attributes[propname]
1384
1389
            def Approve(self, approve, dbus_interface):
1385
1390
                testcase.assertEqual(dbus_interface,
1386
1391
                                     client_dbus_interface)
1458
1463
 
1459
1464
class TestBaseCommands(TestCommand):
1460
1465
 
1461
 
    def test_is_enabled(self):
1462
 
        self.assertTrue(all(command.IsEnabled().is_enabled(client,
1463
 
                                                      properties)
1464
 
                            for client, properties
1465
 
                            in self.clients.items()))
1466
 
 
1467
 
    def test_is_enabled_run_exits_successfully(self):
 
1466
    def test_IsEnabled_exits_successfully(self):
1468
1467
        with self.assertRaises(SystemExit) as e:
1469
1468
            command.IsEnabled().run(self.one_client)
1470
1469
        if e.exception.code is not None:
1472
1471
        else:
1473
1472
            self.assertIsNone(e.exception.code)
1474
1473
 
1475
 
    def test_is_enabled_run_exits_with_failure(self):
 
1474
    def test_IsEnabled_exits_with_failure(self):
1476
1475
        self.client.attributes["Enabled"] = dbus.Boolean(False)
1477
1476
        with self.assertRaises(SystemExit) as e:
1478
1477
            command.IsEnabled().run(self.one_client)
1481
1480
        else:
1482
1481
            self.assertIsNotNone(e.exception.code)
1483
1482
 
1484
 
    def test_approve(self):
 
1483
    def test_Approve(self):
1485
1484
        command.Approve().run(self.clients, self.bus)
1486
1485
        for clientpath in self.clients:
1487
1486
            client = self.bus.get_object(dbus_busname, clientpath)
1488
1487
            self.assertIn(("Approve", (True, client_dbus_interface)),
1489
1488
                          client.calls)
1490
1489
 
1491
 
    def test_deny(self):
 
1490
    def test_Deny(self):
1492
1491
        command.Deny().run(self.clients, self.bus)
1493
1492
        for clientpath in self.clients:
1494
1493
            client = self.bus.get_object(dbus_busname, clientpath)
1495
1494
            self.assertIn(("Approve", (False, client_dbus_interface)),
1496
1495
                          client.calls)
1497
1496
 
1498
 
    def test_remove(self):
 
1497
    def test_Remove(self):
1499
1498
        class MockMandos(object):
1500
1499
            def __init__(self):
1501
1500
                self.calls = []
1502
1501
            def RemoveClient(self, dbus_path):
1503
1502
                self.calls.append(("RemoveClient", (dbus_path,)))
1504
1503
        mandos = MockMandos()
1505
 
        super(TestBaseCommands, self).setUp()
1506
1504
        command.Remove().run(self.clients, self.bus, mandos)
1507
 
        self.assertEqual(len(mandos.calls), 2)
1508
1505
        for clientpath in self.clients:
1509
1506
            self.assertIn(("RemoveClient", (clientpath,)),
1510
1507
                          mandos.calls)
1696
1693
            for clientpath in self.clients:
1697
1694
                client = self.bus.get_object(dbus_busname, clientpath)
1698
1695
                old_value = client.attributes[self.propname]
1699
 
                self.assertNotIsInstance(old_value, self.Unique)
1700
1696
                client.attributes[self.propname] = self.Unique()
1701
1697
            self.run_command(value_to_set, self.clients)
1702
1698
            for clientpath in self.clients: