Skip to content

Commit d9b7d13

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Add cli tests for --verify and friends"
2 parents 3ee99dc + 2c4b878 commit d9b7d13

2 files changed

Lines changed: 55 additions & 3 deletions

File tree

‎openstackclient/shell.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,14 +187,14 @@ def build_option_parser(self, description, version):
187187
verify_group = parser.add_mutually_exclusive_group()
188188
verify_group.add_argument(
189189
'--verify',
190+
action='store_true',
190191
default=None,
191-
action='store_false',
192192
help='Verify server certificate (default)',
193193
)
194194
verify_group.add_argument(
195195
'--insecure',
196-
default=None,
197196
action='store_true',
197+
default=None,
198198
help='Disable server certificate verification',
199199
)
200200
parser.add_argument(

‎openstackclient/tests/test_shell.py‎

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -527,13 +527,65 @@ def tearDown(self):
527527
super(TestShellCli, self).tearDown()
528528
os.environ = self.orig_env
529529

530-
def test_shell_args(self):
530+
def test_shell_args_no_options(self):
531531
_shell = make_shell()
532532
with mock.patch("openstackclient.shell.OpenStackShell.initialize_app",
533533
self.app):
534534
fake_execute(_shell, "list user")
535535
self.app.assert_called_with(["list", "user"])
536536

537+
def test_shell_args_ca_options(self):
538+
_shell = make_shell()
539+
540+
# NOTE(dtroyer): The commented out asserts below are the desired
541+
# behaviour and will be uncommented when the
542+
# handling for --verify and --insecure is fixed.
543+
544+
# Default
545+
fake_execute(_shell, "list user")
546+
self.assertIsNone(_shell.options.verify)
547+
self.assertIsNone(_shell.options.insecure)
548+
self.assertEqual('', _shell.options.os_cacert)
549+
self.assertTrue(_shell.verify)
550+
551+
# --verify
552+
fake_execute(_shell, "--verify list user")
553+
self.assertTrue(_shell.options.verify)
554+
self.assertIsNone(_shell.options.insecure)
555+
self.assertEqual('', _shell.options.os_cacert)
556+
self.assertTrue(_shell.verify)
557+
558+
# --insecure
559+
fake_execute(_shell, "--insecure list user")
560+
self.assertIsNone(_shell.options.verify)
561+
self.assertTrue(_shell.options.insecure)
562+
self.assertEqual('', _shell.options.os_cacert)
563+
self.assertFalse(_shell.verify)
564+
565+
# --os-cacert
566+
fake_execute(_shell, "--os-cacert foo list user")
567+
self.assertIsNone(_shell.options.verify)
568+
self.assertIsNone(_shell.options.insecure)
569+
self.assertEqual('foo', _shell.options.os_cacert)
570+
self.assertTrue(_shell.verify)
571+
572+
# --os-cacert and --verify
573+
fake_execute(_shell, "--os-cacert foo --verify list user")
574+
self.assertTrue(_shell.options.verify)
575+
self.assertIsNone(_shell.options.insecure)
576+
self.assertEqual('foo', _shell.options.os_cacert)
577+
self.assertTrue(_shell.verify)
578+
579+
# --os-cacert and --insecure
580+
# NOTE(dtroyer): This really is a bogus combination, the default is
581+
# to follow the requests.Session convention and let
582+
# --os-cacert override --insecure
583+
fake_execute(_shell, "--os-cacert foo --insecure list user")
584+
self.assertIsNone(_shell.options.verify)
585+
self.assertTrue(_shell.options.insecure)
586+
self.assertEqual('foo', _shell.options.os_cacert)
587+
self.assertTrue(_shell.verify)
588+
537589
def test_default_env(self):
538590
flag = ""
539591
kwargs = {

0 commit comments

Comments
 (0)