def test_csv_file_dir(self): # Checking default value home_dir = pwd.getpwnam(getpass.getuser()).pw_dir self.assertEqual(home_dir + os.sep + '.bind10' + os.sep, bindcmd.BindCmdInterpreter().csv_file_dir) new_csv_dir = '/something/different/' custom_cmd = bindcmd.BindCmdInterpreter(csv_file_dir=new_csv_dir) self.assertEqual(new_csv_dir, custom_cmd.csv_file_dir)
def setUp(self): self.tool = bindcmd.BindCmdInterpreter() mod_info = ModuleInfo(name="foo") self.tool.add_module_info(mod_info) self.tool.config_data = FakeCCSession() self.stdout_backup = sys.stdout self.printed_messages = [] self.tool._print = self.store_print
def _create_bindcmd(self): """Create one bindcmd""" self._cmd = CommandInfo(name="load") self.module = ModuleInfo(name="zone") self.tool = bindcmd.BindCmdInterpreter() for random_str in self.random_names: self._cmd.add_param(ParamInfo(name=random_str)) self.module.add_command(CommandInfo(name=random_str)) self.tool.add_module_info(ModuleInfo(name=random_str))
def test_get_saved_user_info(self): with open(os.devnull, 'w') as f: sys.stdout = f cmd = bindcmd.BindCmdInterpreter() users = cmd._get_saved_user_info('/notexist', 'csv_file.csv') self.assertEqual([], users) csvfilename = 'csv_file.csv' self._create_invalid_csv_file(csvfilename) users = cmd._get_saved_user_info('./', csvfilename) self.assertEqual([], users) os.remove(csvfilename)
def _create_bindcmd(self): """Create one bindcmd""" tool = bindcmd.BindCmdInterpreter() string_spec = { 'item_type': 'string', 'item_optional': False, 'item_default': '' } int_spec = { 'item_type': 'integer', 'item_optional': False, 'item_default': 10 } zone_file_param = ParamInfo(name="zone_file", param_spec=string_spec) zone_name = ParamInfo(name='zone_name', param_spec=string_spec) load_cmd = CommandInfo(name="load") load_cmd.add_param(zone_file_param) load_cmd.add_param(zone_name) param_master = ParamInfo(name="master", optional=True, param_spec=string_spec) param_master = ParamInfo(name="port", optional=True, param_spec=int_spec) param_allow_update = ParamInfo(name="allow_update", optional=True, param_spec=string_spec) set_cmd = CommandInfo(name="set") set_cmd.add_param(param_master) set_cmd.add_param(param_allow_update) set_cmd.add_param(zone_name) reload_all_cmd = CommandInfo(name="reload_all") zone_module = ModuleInfo(name="zone") zone_module.add_command(load_cmd) zone_module.add_command(set_cmd) zone_module.add_command(reload_all_cmd) tool.add_module_info(zone_module) return tool