2070
2070
def runTest(self):
2071
2071
if not hasattr(self, "command"):
2072
2072
return # Abstract TestCase class
2073
values_to_get = getattr(self, "values_to_get",
2075
for value_to_set, value_to_get in zip(self.values_to_set,
2077
for clientpath in self.bus.clients:
2078
self.bus.clients[clientpath][self.propname] = Unique()
2079
self.run_command(value_to_set, self.bus.clients)
2080
for clientpath in self.bus.clients:
2081
value = self.bus.clients[clientpath][self.propname]
2074
if hasattr(self, "values_to_set"):
2075
cmd_args = [(value,) for value in self.values_to_set]
2076
values_to_get = getattr(self, "values_to_get",
2079
cmd_args = [() for x in range(len(self.values_to_get))]
2080
values_to_get = self.values_to_get
2081
for value_to_get, cmd_arg in zip(values_to_get, cmd_args):
2082
for clientpath in self.bus.clients:
2083
self.bus.clients[clientpath][self.propname] = (
2085
self.command(*cmd_arg).run(self.bus.clients, self.bus)
2086
for clientpath in self.bus.clients:
2087
value = (self.bus.clients[clientpath]
2082
2089
self.assertNotIsInstance(value, Unique)
2083
2090
self.assertEqual(value_to_get, value)
2085
def run_command(self, value, clients):
2086
self.command().run(clients, self.bus)
2089
2093
class TestEnableCmd(TestPropertySetterCmd):
2090
2094
command = command.Enable
2091
2095
propname = "Enabled"
2092
values_to_set = [True]
2096
values_to_get = [True]
2095
2099
class TestDisableCmd(TestPropertySetterCmd):
2096
2100
command = command.Disable
2097
2101
propname = "Enabled"
2098
values_to_set = [False]
2102
values_to_get = [False]
2101
2105
class TestBumpTimeoutCmd(TestPropertySetterCmd):
2102
2106
command = command.BumpTimeout
2103
2107
propname = "LastCheckedOK"
2104
values_to_set = [""]
2108
values_to_get = [""]
2107
2111
class TestStartCheckerCmd(TestPropertySetterCmd):
2108
2112
command = command.StartChecker
2109
2113
propname = "CheckerRunning"
2110
values_to_set = [True]
2114
values_to_get = [True]
2113
2117
class TestStopCheckerCmd(TestPropertySetterCmd):
2114
2118
command = command.StopChecker
2115
2119
propname = "CheckerRunning"
2116
values_to_set = [False]
2120
values_to_get = [False]
2119
2123
class TestApproveByDefaultCmd(TestPropertySetterCmd):
2120
2124
command = command.ApproveByDefault
2121
2125
propname = "ApprovedByDefault"
2122
values_to_set = [True]
2126
values_to_get = [True]
2125
2129
class TestDenyByDefaultCmd(TestPropertySetterCmd):
2126
2130
command = command.DenyByDefault
2127
2131
propname = "ApprovedByDefault"
2128
values_to_set = [False]
2131
class TestPropertySetterValueCmd(TestPropertySetterCmd):
2132
"""Abstract class for tests of PropertySetterValueCmd classes"""
2134
def run_command(self, value, clients):
2135
self.command(value).run(clients, self.bus)
2138
class TestSetCheckerCmd(TestPropertySetterValueCmd):
2132
values_to_get = [False]
2135
class TestSetCheckerCmd(TestPropertySetterCmd):
2139
2136
command = command.SetChecker
2140
2137
propname = "Checker"
2141
2138
values_to_set = ["", ":", "fping -q -- %s"]
2144
class TestSetHostCmd(TestPropertySetterValueCmd):
2141
class TestSetHostCmd(TestPropertySetterCmd):
2145
2142
command = command.SetHost
2146
2143
propname = "Host"
2147
2144
values_to_set = ["192.0.2.3", "client.example.org"]
2150
class TestSetSecretCmd(TestPropertySetterValueCmd):
2147
class TestSetSecretCmd(TestPropertySetterCmd):
2151
2148
command = command.SetSecret
2152
2149
propname = "Secret"
2153
2150
values_to_set = [io.BytesIO(b""),