|
@@ -19,8 +19,10 @@ import isc.cc.data
|
|
|
import os
|
|
|
import pwd
|
|
|
import getpass
|
|
|
+from optparse import OptionParser
|
|
|
from isc.config.config_data import ConfigData, MultiConfigData
|
|
|
from isc.config.module_spec import ModuleSpec
|
|
|
+from bindctl.bindctl_source import set_bindctl_options
|
|
|
from bindctl import cmdparse
|
|
|
from bindctl import bindcmd
|
|
|
from bindctl.moduleinfo import *
|
|
@@ -368,6 +370,40 @@ class TestBindCmdInterpreter(unittest.TestCase):
|
|
|
self.assertEqual([], users)
|
|
|
os.remove(csvfilename)
|
|
|
|
|
|
+
|
|
|
+class TestCommandLineOptions(unittest.TestCase):
|
|
|
+ class FakeParserError(Exception):
|
|
|
+ """An exception thrown from FakeOptionParser on parser error.
|
|
|
+ """
|
|
|
+ pass
|
|
|
+
|
|
|
+ class FakeOptionParser(OptionParser):
|
|
|
+ """This fake class emulates the OptionParser class with customized
|
|
|
+ error handling for the convenient of tests.
|
|
|
+ """
|
|
|
+ def __init__(self):
|
|
|
+ OptionParser.__init__(self)
|
|
|
+
|
|
|
+ def error(self, msg):
|
|
|
+ raise TestCommandLineOptions.FakeParserError
|
|
|
+
|
|
|
+ def setUp(self):
|
|
|
+ self.parser = self.FakeOptionParser()
|
|
|
+ set_bindctl_options(self.parser)
|
|
|
+
|
|
|
+ def test_csv_file_dir(self):
|
|
|
+ # by default the option is "undefined"
|
|
|
+ (options, _) = self.parser.parse_args([])
|
|
|
+ self.assertEqual(None, options.csv_file_dir)
|
|
|
+
|
|
|
+ # specify the option, valid case.
|
|
|
+ (options, _) = self.parser.parse_args(['--csv-file-dir', 'some_dir'])
|
|
|
+ self.assertEqual('some_dir', options.csv_file_dir)
|
|
|
+
|
|
|
+ # missing option arg; should trigger parser error.
|
|
|
+ self.assertRaises(self.FakeParserError, self.parser.parse_args,
|
|
|
+ ['--csv-file-dir'])
|
|
|
+
|
|
|
if __name__== "__main__":
|
|
|
unittest.main()
|
|
|
|