=== modified file 'mandos-ctl' --- mandos-ctl 2019-03-12 20:13:34 +0000 +++ mandos-ctl 2019-03-12 20:24:58 +0000 @@ -666,13 +666,13 @@ def string_from_client(self, client, key): return self.valuetostring(client[key], key) - @staticmethod - def valuetostring(value, keyword): + @classmethod + def valuetostring(cls, value, keyword): if isinstance(value, dbus.Boolean): return "Yes" if value else "No" if keyword in ("Timeout", "Interval", "ApprovalDelay", "ApprovalDuration", "ExtendedTimeout"): - return milliseconds_to_string(value) + return cls.milliseconds_to_string(value) return str(value) def header_line(self, format_string): @@ -683,14 +683,15 @@ **{key: self.string_from_client(client, key) for key in self.keywords}) - -def milliseconds_to_string(ms): - td = datetime.timedelta(0, 0, 0, ms) - return ("{days}{hours:02}:{minutes:02}:{seconds:02}" - .format(days="{}T".format(td.days) if td.days else "", - hours=td.seconds // 3600, - minutes=(td.seconds % 3600) // 60, - seconds=td.seconds % 60)) + @staticmethod + def milliseconds_to_string(ms): + td = datetime.timedelta(0, 0, 0, ms) + return ("{days}{hours:02}:{minutes:02}:{seconds:02}" + .format(days="{}T".format(td.days) + if td.days else "", + hours=td.seconds // 3600, + minutes=(td.seconds % 3600) // 60, + seconds=td.seconds % 60)) class PropertyCmd(Command): @@ -1236,7 +1237,7 @@ ApprovedByDefault=dbus.Boolean(False), LastApprovalRequest="2019-01-03T00:00:00", ApprovalDelay=30000, - ApprovalDuration=1000, + ApprovalDuration=93785000, Checker=":", ExtendedTimeout=900000, Expires="2019-02-05T00:00:00", @@ -1361,7 +1362,7 @@ "ApprovedByDefault": False, "LastApprovalRequest": "2019-01-03T00:00:00", "ApprovalDelay": 30000, - "ApprovalDuration": 1000, + "ApprovalDuration": 93785000, "Checker": ":", "ExtendedTimeout": 900000, "Expires": "2019-02-05T00:00:00", @@ -1458,7 +1459,7 @@ ),( "Approval Duration ", "00:00:01 ", - "00:00:01 ", + "1T02:03:05 ", ),( "Checker ", "fping -q -- %(host)s ", @@ -1491,20 +1492,6 @@ self.assertEqual(output, expected_output) -class Test_milliseconds_to_string(unittest.TestCase): - def test_all(self): - self.assertEqual(milliseconds_to_string(93785000), - "1T02:03:05") - def test_no_days(self): - self.assertEqual(milliseconds_to_string(7385000), "02:03:05") - def test_all_zero(self): - self.assertEqual(milliseconds_to_string(0), "00:00:00") - def test_no_fractional_seconds(self): - self.assertEqual(milliseconds_to_string(400), "00:00:00") - self.assertEqual(milliseconds_to_string(900), "00:00:00") - self.assertEqual(milliseconds_to_string(1900), "00:00:01") - - class Unique(object): """Class for objects which exist only to be unique objects, since unittest.mock.sentinel only exists in Python 3.3"""