765
765
self.assertTrue(getattr(warning_filter, "found", False))
766
766
self.assertEqual(value, datetime.timedelta(0, 7200))
768
class Test_TableOfClients(unittest.TestCase):
769
class TestCmd(unittest.TestCase):
770
"""Abstract class for tests of command classes"""
770
self.tableheaders = {
774
"Bool": "A D-BUS Boolean",
775
"NonDbusBoolean": "A Non-D-BUS Boolean",
776
"Integer": "An Integer",
777
"Timeout": "Timedelta 1",
778
"Interval": "Timedelta 2",
779
"ApprovalDelay": "Timedelta 3",
780
"ApprovalDuration": "Timedelta 4",
781
"ExtendedTimeout": "Timedelta 5",
782
"String": "A String",
784
self.keywords = ["Attr1", "AttrTwo"]
790
"Bool": dbus.Boolean(False),
791
"NonDbusBoolean": False,
795
"ApprovalDelay": 2000,
796
"ApprovalDuration": 3000,
797
"ExtendedTimeout": 4000,
804
"Bool": dbus.Boolean(True),
805
"NonDbusBoolean": True,
808
"Interval": 93786000,
809
"ApprovalDelay": 93787000,
810
"ApprovalDuration": 93788000,
811
"ExtendedTimeout": 93789000,
812
"String": "A huge string which will not fit," * 10,
815
def test_short_header(self):
816
text = str(TableOfClients(self.clients, self.keywords,
823
self.assertEqual(text, expected_text)
824
def test_booleans(self):
825
keywords = ["Bool", "NonDbusBoolean"]
826
text = str(TableOfClients(self.clients, keywords,
829
A D-BUS Boolean A Non-D-BUS Boolean
833
self.assertEqual(text, expected_text)
834
def test_milliseconds_detection(self):
835
keywords = ["Integer", "Timeout", "Interval", "ApprovalDelay",
836
"ApprovalDuration", "ExtendedTimeout"]
837
text = str(TableOfClients(self.clients, keywords,
840
An Integer Timedelta 1 Timedelta 2 Timedelta 3 Timedelta 4 Timedelta 5
841
0 00:00:00 00:00:01 00:00:02 00:00:03 00:00:04
842
1 1T02:03:05 1T02:03:06 1T02:03:07 1T02:03:08 1T02:03:09
844
self.assertEqual(text, expected_text)
845
def test_empty_and_long_string_values(self):
846
keywords = ["String"]
847
text = str(TableOfClients(self.clients, keywords,
852
A huge string which will not fit,A huge string which will not fit,A huge string which will not fit,A huge string which will not fit,A huge string which will not fit,A huge string which will not fit,A huge string which will not fit,A huge string which will not fit,A huge string which will not fit,A huge string which will not fit,
854
self.assertEqual(text, expected_text)
773
class MockClient(object):
774
def __init__(self, name, **attributes):
775
self.__dbus_object_path__ = "objpath_{}".format(name)
776
self.attributes = attributes
777
self.attributes["Name"] = name
778
def Set(interface, property, value,
779
properties_interface):
780
testcase.assertEqual(interface, client_interface)
781
testcase.assertEqual(properties_interface,
782
dbus.PROPERTIES_IFACE)
783
self.attributes[property] = value
784
def Get(interface, property, properties_interface):
785
testcase.assertEqual(interface, client_interface)
786
testcase.assertEqual(properties_interface,
787
dbus.PROPERTIES_IFACE)
788
return self.attributes[property]
789
def __getitem__(self, key):
790
return self.attributes[key]
791
self.clients = collections.OrderedDict([
795
KeyID=("92ed150794387c03ce684574b1139a65"
796
"94a34f895daaaf09fd8ea90a27cddb12"),
798
Host="foo.example.org",
799
Enabled=dbus.Boolean(True),
801
LastCheckedOK="2019-02-03T00:00:00",
802
Created="2019-01-02T00:00:00",
804
Fingerprint=("778827225BA7DE539C5A"
805
"7CFA59CFF7CDBD9A5920"),
806
CheckerRunning=dbus.Boolean(False),
807
LastEnabled="2019-01-03T00:00:00",
808
ApprovalPending=dbus.Boolean(False),
809
ApprovedByDefault=dbus.Boolean(True),
810
LastApprovalRequest="",
812
ApprovalDuration=1000,
813
Checker="fping -q -- %(host)s",
814
ExtendedTimeout=900000,
815
Expires="2019-02-04T00:00:00",
816
LastCheckerStatus=0)),
820
KeyID=("0558568eedd67d622f5c83b35a115f79"
821
"6ab612cff5ad227247e46c2b020f441c"),
824
Enabled=dbus.Boolean(True),
826
LastCheckedOK="2019-02-04T00:00:00",
827
Created="2019-01-03T00:00:00",
829
Fingerprint=("3E393AEAEFB84C7E89E2"
830
"F547B3A107558FCA3A27"),
831
CheckerRunning=dbus.Boolean(True),
832
LastEnabled="2019-01-04T00:00:00",
833
ApprovalPending=dbus.Boolean(False),
834
ApprovedByDefault=dbus.Boolean(False),
835
LastApprovalRequest="2019-01-03T00:00:00",
837
ApprovalDuration=1000,
839
ExtendedTimeout=900000,
840
Expires="2019-02-05T00:00:00",
841
LastCheckerStatus=-2)),
844
class TestPrintTableCmd(TestCmd):
845
def test_normal(self):
846
output = PrintTableCmd().output(self.clients)
847
expected_output = """
848
Name Enabled Timeout Last Successful Check
849
foo Yes 00:05:00 2019-02-03T00:00:00
850
barbar Yes 00:05:00 2019-02-04T00:00:00
852
self.assertEqual(output, expected_output)
853
def test_verbose(self):
854
output = PrintTableCmd(verbose=True).output(self.clients)
855
expected_output = """
856
Name Enabled Timeout Last Successful Check Created Interval Host Key ID Fingerprint Check Is Running Last Enabled Approval Is Pending Approved By Default Last Approval Request Approval Delay Approval Duration Checker Extended Timeout Expires Last Checker Status
857
foo Yes 00:05:00 2019-02-03T00:00:00 2019-01-02T00:00:00 00:02:00 foo.example.org 92ed150794387c03ce684574b1139a6594a34f895daaaf09fd8ea90a27cddb12 778827225BA7DE539C5A7CFA59CFF7CDBD9A5920 No 2019-01-03T00:00:00 No Yes 00:00:00 00:00:01 fping -q -- %(host)s 00:15:00 2019-02-04T00:00:00 0
858
barbar Yes 00:05:00 2019-02-04T00:00:00 2019-01-03T00:00:00 00:02:00 192.0.2.3 0558568eedd67d622f5c83b35a115f796ab612cff5ad227247e46c2b020f441c 3E393AEAEFB84C7E89E2F547B3A107558FCA3A27 Yes 2019-01-04T00:00:00 No No 2019-01-03T00:00:00 00:00:30 00:00:01 : 00:15:00 2019-02-05T00:00:00 -2
860
self.assertEqual(output, expected_output)
861
def test_one_client(self):
862
output = PrintTableCmd().output({"foo": self.clients["foo"]})
863
expected_output = """
864
Name Enabled Timeout Last Successful Check
865
foo Yes 00:05:00 2019-02-03T00:00:00
867
self.assertEqual(output, expected_output)