summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichal Dulko <michal.dulko@intel.com>2015-02-09 14:32:17 +0100
committerMichal Dulko <michal.dulko@intel.com>2015-02-09 14:32:17 +0100
commitb47925eda1a674ee2497ec627eee089fbd6e1ac0 (patch)
tree690f213df57d8cc27aa3dd129e26cc276346518d
parent1c377212876d0b21686e016375d4319891f575f8 (diff)
downloadpython-glanceclient-b47925eda1a674ee2497ec627eee089fbd6e1ac0.tar.gz
Unit tests covering missing username or password
After fixing message displayed when client is executed without required environment variables exported (OS_USERNAME, OS_PASSWORD, OS_PROJECT_NAME, OS_AUTH_URL) regression tests should be added. I've also fixed an issue causing tests using make_env method to always use FAKE_V2_ENV, even in ShellTestWithKeystoneV3Auth. Change-Id: I800c8fa11ee45d19f179bd030426db86a93d9f6a Closes-Bug: 1419788 Partial-Bug: 1355252
-rw-r--r--tests/test_shell.py52
1 files changed, 50 insertions, 2 deletions
diff --git a/tests/test_shell.py b/tests/test_shell.py
index 2721655..0974f65 100644
--- a/tests/test_shell.py
+++ b/tests/test_shell.py
@@ -69,8 +69,8 @@ class ShellTest(utils.TestCase):
auth_plugin = 'keystoneclient.auth.identity.v2.Password'
# Patch os.environ to avoid required auth info
- def make_env(self, exclude=None, fake_env=FAKE_V2_ENV):
- env = dict((k, v) for k, v in fake_env.items() if k != exclude)
+ def make_env(self, exclude=None):
+ env = dict((k, v) for k, v in self.auth_env.items() if k != exclude)
self.useFixture(fixtures.MonkeyPatch('os.environ', env))
def setUp(self):
@@ -298,6 +298,54 @@ class ShellTest(utils.TestCase):
except SystemExit as ex:
self.assertEqual(130, ex.code)
+ @mock.patch('glanceclient.v1.client.Client')
+ def test_auth_plugin_invocation_without_username_with_v1(self, v1_client):
+ self.make_env(exclude='OS_USERNAME')
+ args = 'image-list'
+ glance_shell = openstack_shell.OpenStackImagesShell()
+ self.assertRaises(exc.CommandError, glance_shell.main, args.split())
+
+ @mock.patch('glanceclient.v2.client.Client')
+ def test_auth_plugin_invocation_without_username_with_v2(self, v2_client):
+ self.make_env(exclude='OS_USERNAME')
+ args = '--os-image-api-version 2 image-list'
+ glance_shell = openstack_shell.OpenStackImagesShell()
+ self.assertRaises(exc.CommandError, glance_shell.main, args.split())
+
+ @mock.patch('glanceclient.v1.client.Client')
+ def test_auth_plugin_invocation_without_auth_url_with_v1(self, v1_client):
+ self.make_env(exclude='OS_AUTH_URL')
+ args = 'image-list'
+ glance_shell = openstack_shell.OpenStackImagesShell()
+ self.assertRaises(exc.CommandError, glance_shell.main, args.split())
+
+ @mock.patch('glanceclient.v2.client.Client')
+ def test_auth_plugin_invocation_without_auth_url_with_v2(self, v2_client):
+ self.make_env(exclude='OS_AUTH_URL')
+ args = '--os-image-api-version 2 image-list'
+ glance_shell = openstack_shell.OpenStackImagesShell()
+ self.assertRaises(exc.CommandError, glance_shell.main, args.split())
+
+ @mock.patch('glanceclient.v1.client.Client')
+ def test_auth_plugin_invocation_without_tenant_with_v1(self, v1_client):
+ if 'OS_TENANT_NAME' in os.environ:
+ self.make_env(exclude='OS_TENANT_NAME')
+ if 'OS_PROJECT_ID' in os.environ:
+ self.make_env(exclude='OS_PROJECT_ID')
+ args = 'image-list'
+ glance_shell = openstack_shell.OpenStackImagesShell()
+ self.assertRaises(exc.CommandError, glance_shell.main, args.split())
+
+ @mock.patch('glanceclient.v2.client.Client')
+ def test_auth_plugin_invocation_without_tenant_with_v2(self, v2_client):
+ if 'OS_TENANT_NAME' in os.environ:
+ self.make_env(exclude='OS_TENANT_NAME')
+ if 'OS_PROJECT_ID' in os.environ:
+ self.make_env(exclude='OS_PROJECT_ID')
+ args = '--os-image-api-version 2 image-list'
+ glance_shell = openstack_shell.OpenStackImagesShell()
+ self.assertRaises(exc.CommandError, glance_shell.main, args.split())
+
class ShellTestWithKeystoneV3Auth(ShellTest):
# auth environment to use