diff options
Diffstat (limited to 'openstackclient/tests/common')
| -rw-r--r-- | openstackclient/tests/common/test_clientmanager.py | 2 | ||||
| -rw-r--r-- | openstackclient/tests/common/test_command.py | 1 | ||||
| -rw-r--r-- | openstackclient/tests/common/test_commandmanager.py | 2 | ||||
| -rw-r--r-- | openstackclient/tests/common/test_logs.py | 2 | ||||
| -rw-r--r-- | openstackclient/tests/common/test_parseractions.py | 129 | ||||
| -rw-r--r-- | openstackclient/tests/common/test_timing.py | 2 | ||||
| -rw-r--r-- | openstackclient/tests/common/test_utils.py | 1 |
7 files changed, 138 insertions, 1 deletions
diff --git a/openstackclient/tests/common/test_clientmanager.py b/openstackclient/tests/common/test_clientmanager.py index ef46f61c..2bd9e783 100644 --- a/openstackclient/tests/common/test_clientmanager.py +++ b/openstackclient/tests/common/test_clientmanager.py @@ -47,6 +47,7 @@ class Container(object): class FakeOptions(object): + def __init__(self, **kwargs): for option in auth.OPTIONS_LIST: setattr(self, option.replace('-', '_'), None) @@ -71,6 +72,7 @@ class TestClientCache(utils.TestCase): class TestClientManager(utils.TestCase): + def setUp(self): super(TestClientManager, self).setUp() self.mock = mock.Mock() diff --git a/openstackclient/tests/common/test_command.py b/openstackclient/tests/common/test_command.py index 1b2584bd..7467d9eb 100644 --- a/openstackclient/tests/common/test_command.py +++ b/openstackclient/tests/common/test_command.py @@ -19,6 +19,7 @@ from openstackclient.tests import utils as test_utils class FakeCommand(command.Command): + def take_action(self, parsed_args): pass diff --git a/openstackclient/tests/common/test_commandmanager.py b/openstackclient/tests/common/test_commandmanager.py index 37dc90fe..e2b274dc 100644 --- a/openstackclient/tests/common/test_commandmanager.py +++ b/openstackclient/tests/common/test_commandmanager.py @@ -20,6 +20,7 @@ from openstackclient.tests import utils class FakeCommand(object): + @classmethod def load(cls): return cls @@ -48,6 +49,7 @@ class FakeCommandManager(commandmanager.CommandManager): class TestCommandManager(utils.TestCase): + def test_add_command_group(self): mgr = FakeCommandManager('test') diff --git a/openstackclient/tests/common/test_logs.py b/openstackclient/tests/common/test_logs.py index a319533a..0386cdfd 100644 --- a/openstackclient/tests/common/test_logs.py +++ b/openstackclient/tests/common/test_logs.py @@ -66,6 +66,7 @@ class TestContext(utils.TestCase): class TestFileFormatter(utils.TestCase): + def test_nothing(self): formatter = logs._FileFormatter() self.assertEqual(('%(asctime)s.%(msecs)03d %(process)d %(levelname)s ' @@ -93,6 +94,7 @@ class TestFileFormatter(utils.TestCase): class TestLogConfigurator(utils.TestCase): + def setUp(self): super(TestLogConfigurator, self).setUp() self.options = mock.Mock() diff --git a/openstackclient/tests/common/test_parseractions.py b/openstackclient/tests/common/test_parseractions.py index 0109a3f3..a4ee07bf 100644 --- a/openstackclient/tests/common/test_parseractions.py +++ b/openstackclient/tests/common/test_parseractions.py @@ -61,6 +61,135 @@ class TestKeyValueAction(utils.TestCase): self.assertDictEqual(expect, actual) +class TestMultiKeyValueAction(utils.TestCase): + + def setUp(self): + super(TestMultiKeyValueAction, self).setUp() + + self.parser = argparse.ArgumentParser() + + # Set up our typical usage + self.parser.add_argument( + '--test', + metavar='req1=xxx,req2=yyy', + action=parseractions.MultiKeyValueAction, + dest='test', + default=None, + required_keys=['req1', 'req2'], + optional_keys=['opt1', 'opt2'], + help='Test' + ) + + def test_good_values(self): + results = self.parser.parse_args([ + '--test', 'req1=aaa,req2=bbb', + '--test', 'req1=,req2=', + ]) + + actual = getattr(results, 'test', []) + expect = [ + {'req1': 'aaa', 'req2': 'bbb'}, + {'req1': '', 'req2': ''}, + ] + # Need to sort the lists before comparing them + key = lambda x: x['req1'] + expect.sort(key=key) + actual.sort(key=key) + self.assertListEqual(expect, actual) + + def test_empty_required_optional(self): + self.parser.add_argument( + '--test-empty', + metavar='req1=xxx,req2=yyy', + action=parseractions.MultiKeyValueAction, + dest='test_empty', + default=None, + required_keys=[], + optional_keys=[], + help='Test' + ) + + results = self.parser.parse_args([ + '--test-empty', 'req1=aaa,req2=bbb', + '--test-empty', 'req1=,req2=', + ]) + + actual = getattr(results, 'test_empty', []) + expect = [ + {'req1': 'aaa', 'req2': 'bbb'}, + {'req1': '', 'req2': ''}, + ] + # Need to sort the lists before comparing them + key = lambda x: x['req1'] + expect.sort(key=key) + actual.sort(key=key) + self.assertListEqual(expect, actual) + + def test_error_values_with_comma(self): + self.assertRaises( + argparse.ArgumentTypeError, + self.parser.parse_args, + [ + '--test', 'mmm,nnn=zzz', + ] + ) + + def test_error_values_without_comma(self): + self.assertRaises( + argparse.ArgumentTypeError, + self.parser.parse_args, + [ + '--test', 'mmmnnn', + ] + ) + + def test_missing_key(self): + self.assertRaises( + argparse.ArgumentTypeError, + self.parser.parse_args, + [ + '--test', 'req2=ddd', + ] + ) + + def test_invalid_key(self): + self.assertRaises( + argparse.ArgumentTypeError, + self.parser.parse_args, + [ + '--test', 'req1=aaa,req2=bbb,aaa=req1', + ] + ) + + def test_required_keys_not_list(self): + self.assertRaises( + TypeError, + self.parser.add_argument, + '--test-required-dict', + metavar='req1=xxx,req2=yyy', + action=parseractions.MultiKeyValueAction, + dest='test_required_dict', + default=None, + required_keys={'aaa': 'bbb'}, + optional_keys=['opt1', 'opt2'], + help='Test' + ) + + def test_optional_keys_not_list(self): + self.assertRaises( + TypeError, + self.parser.add_argument, + '--test-optional-dict', + metavar='req1=xxx,req2=yyy', + action=parseractions.MultiKeyValueAction, + dest='test_optional_dict', + default=None, + required_keys=['req1', 'req2'], + optional_keys={'aaa': 'bbb'}, + help='Test' + ) + + class TestNonNegativeAction(utils.TestCase): def setUp(self): diff --git a/openstackclient/tests/common/test_timing.py b/openstackclient/tests/common/test_timing.py index c4c738b2..e33bb7ae 100644 --- a/openstackclient/tests/common/test_timing.py +++ b/openstackclient/tests/common/test_timing.py @@ -75,7 +75,7 @@ class TestTiming(utils.TestCommand): def test_timing_list(self): self.app.timing_data = [( timing_url, - datetime.timedelta(microseconds=timing_elapsed*1000000), + datetime.timedelta(microseconds=timing_elapsed * 1000000), )] arglist = [] diff --git a/openstackclient/tests/common/test_utils.py b/openstackclient/tests/common/test_utils.py index da7ce063..95bce458 100644 --- a/openstackclient/tests/common/test_utils.py +++ b/openstackclient/tests/common/test_utils.py @@ -250,6 +250,7 @@ class NoUniqueMatch(Exception): class TestFindResource(test_utils.TestCase): + def setUp(self): super(TestFindResource, self).setUp() self.name = 'legos' |
