From a0d65e4ccddffbf2b1596332ef67733583554bbc Mon Sep 17 00:00:00 2001
From: Alistair Coles <alistair.coles@hpe.com>
Date: Thu, 5 May 2016 15:25:16 +0100
Subject: [PATCH] Tighten up testing for sloppy auth version

The existing test that os-identity-api-version=2 would
result in the correct auth_version=2.0 (note 2 -> 2.0)
does not verify the sloppy version handling code path.
When auth, key and user options are all missing the
auth version is always set to 2.0 so the test will always
pass. Adding auth, key and user options to the test command
will cause the test to verify that the os-identity-api-version
option was used and mapped to 2.0.

Change-Id: Ifa10cd2b8bf81c082d5e3fa846f993871194fea0
---
 tests/unit/test_shell.py | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/tests/unit/test_shell.py b/tests/unit/test_shell.py
index f921721f..faf60586 100644
--- a/tests/unit/test_shell.py
+++ b/tests/unit/test_shell.py
@@ -1528,7 +1528,7 @@ class TestParsing(TestBase):
                    "auth_url": "http://example.com:5000/v3",
                    "identity-api-version": "3.0"}
 
-        # check os_identity_api_version is sufficient in place of auth_version
+        # check os_identity_api_version=3.0 is mapped to auth_version=3
         args = _make_args("stat", {}, os_opts, '-')
         result = [None, None]
         fake_command = self._make_fake_command(result)
@@ -1541,13 +1541,19 @@ class TestParsing(TestBase):
                             "auth_url": "http://example.com:5000/v3"}
         self._verify_opts(result[0], expected_opts, expected_os_opts, {})
 
+        # check os_identity_api_version=2 is mapped to auth_version=2.0
+        # A somewhat contrived scenario - we need to pass in the v1 style opts
+        # to prevent auth version defaulting to 2.0 due to lack of v1 style
+        # options. That way we can actually verify that the sloppy 2 was
+        # interpreted and mapped to 2.0
         os_opts = {"password": "secret",
                    "username": "user",
                    "auth_url": "http://example.com:5000/v2.0",
                    "identity-api-version": "2"}
-
-        # check os_identity_api_version is sufficient in place of auth_version
-        args = _make_args("stat", {}, os_opts, '-')
+        opts = {"key": "secret",
+                "user": "user",
+                "auth": "http://example.com:5000/v2.0"}
+        args = _make_args("stat", opts, os_opts, '-')
         result = [None, None]
         fake_command = self._make_fake_command(result)
         with mock.patch.dict(os.environ, {}):