def _assert_invalid_port(self, name_addr_port_tuple_list): arg_list = self._fixture_args(name_addr_port_tuple_list) mock_auth_hosts = self.patch_auth_hosts.start() with self.assertRaises(CmdLineInputError) as cm: host.auth_cmd(self.lib, arg_list, dict_to_modifiers({})) _, addr, port = name_addr_port_tuple_list[-1] self.assertEqual( ("Invalid port number in address '{addr}:{port}', use 1..65535" ).format(addr=addr, port=port), cm.exception.message, ) mock_auth_hosts.assert_not_called() self.patch_auth_hosts.stop()
def _assert_valid_port(self, name_addr_port_tuple_list): arg_list = self._fixture_args(name_addr_port_tuple_list) mock_get_user_and_pass = self.patch_get_user_and_pass.start() mock_auth_hosts = self.patch_auth_hosts.start() host.auth_cmd(self.lib, arg_list, dict_to_modifiers({})) mock_get_user_and_pass.assert_called_once_with() mock_auth_hosts.assert_called_once_with({ name: { "dest_list": [dict( addr=addr if addr.count(":") <= 1 else addr.strip("[]"), port=port, )], "username": "******", "password": "******", } for name, addr, port in name_addr_port_tuple_list }) self.patch_get_user_and_pass.stop() self.patch_auth_hosts.stop()
def test_no_args(self, mock_auth_hosts): with self.assertRaises(CmdLineInputError) as cm: host.auth_cmd(self.lib, [], dict_to_modifiers({})) self.assertEqual("No host specified", cm.exception.message) mock_auth_hosts.assert_not_called()