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