765
757
self.assertTrue(getattr(warning_filter, "found", False))
766
758
self.assertEqual(value, datetime.timedelta(0, 7200))
769
class TestCmd(unittest.TestCase):
770
"""Abstract class for tests of command classes"""
760
class Test_TableOfClients(unittest.TestCase):
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)
762
self.tableheaders = {
766
"Bool": "A D-BUS Boolean",
767
"NonDbusBoolean": "A Non-D-BUS Boolean",
768
"Integer": "An Integer",
769
"Timeout": "Timedelta 1",
770
"Interval": "Timedelta 2",
771
"ApprovalDelay": "Timedelta 3",
772
"ApprovalDuration": "Timedelta 4",
773
"ExtendedTimeout": "Timedelta 5",
774
"String": "A String",
776
self.keywords = ["Attr1", "AttrTwo"]
782
"Bool": dbus.Boolean(False),
783
"NonDbusBoolean": False,
787
"ApprovalDelay": 2000,
788
"ApprovalDuration": 3000,
789
"ExtendedTimeout": 4000,
796
"Bool": dbus.Boolean(True),
797
"NonDbusBoolean": True,
800
"Interval": 93786000,
801
"ApprovalDelay": 93787000,
802
"ApprovalDuration": 93788000,
803
"ExtendedTimeout": 93789000,
804
"String": "A huge string which will not fit," * 10,
807
def test_short_header(self):
808
text = str(TableOfClients(self.clients, self.keywords,
815
self.assertEqual(text, expected_text)
816
def test_booleans(self):
817
keywords = ["Bool", "NonDbusBoolean"]
818
text = str(TableOfClients(self.clients, keywords,
821
A D-BUS Boolean A Non-D-BUS Boolean
825
self.assertEqual(text, expected_text)
826
def test_milliseconds_detection(self):
827
keywords = ["Integer", "Timeout", "Interval", "ApprovalDelay",
828
"ApprovalDuration", "ExtendedTimeout"]
829
text = str(TableOfClients(self.clients, keywords,
832
An Integer Timedelta 1 Timedelta 2 Timedelta 3 Timedelta 4 Timedelta 5
833
0 00:00:00 00:00:01 00:00:02 00:00:03 00:00:04
834
1 1T02:03:05 1T02:03:06 1T02:03:07 1T02:03:08 1T02:03:09
836
self.assertEqual(text, expected_text)
837
def test_empty_and_long_string_values(self):
838
keywords = ["String"]
839
text = str(TableOfClients(self.clients, keywords,
844
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,
846
self.assertEqual(text, expected_text)