Skip to content

Commit 2858645

Browse files
Jenkinsopenstack-gerrit
authored andcommitted
Merge "Unit tests covering missing username or password"
2 parents 9e09211 + b47925e commit 2858645

File tree

1 file changed

+50
-2
lines changed

1 file changed

+50
-2
lines changed

tests/test_shell.py

Lines changed: 50 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,8 @@ class ShellTest(utils.TestCase):
6969
auth_plugin = 'keystoneclient.auth.identity.v2.Password'
7070

7171
# Patch os.environ to avoid required auth info
72-
def make_env(self, exclude=None, fake_env=FAKE_V2_ENV):
73-
env = dict((k, v) for k, v in fake_env.items() if k != exclude)
72+
def make_env(self, exclude=None):
73+
env = dict((k, v) for k, v in self.auth_env.items() if k != exclude)
7474
self.useFixture(fixtures.MonkeyPatch('os.environ', env))
7575

7676
def setUp(self):
@@ -300,6 +300,54 @@ def test_shell_keyboard_interrupt(self, mock_glance_shell):
300300
except SystemExit as ex:
301301
self.assertEqual(130, ex.code)
302302

303+
@mock.patch('glanceclient.v1.client.Client')
304+
def test_auth_plugin_invocation_without_username_with_v1(self, v1_client):
305+
self.make_env(exclude='OS_USERNAME')
306+
args = 'image-list'
307+
glance_shell = openstack_shell.OpenStackImagesShell()
308+
self.assertRaises(exc.CommandError, glance_shell.main, args.split())
309+
310+
@mock.patch('glanceclient.v2.client.Client')
311+
def test_auth_plugin_invocation_without_username_with_v2(self, v2_client):
312+
self.make_env(exclude='OS_USERNAME')
313+
args = '--os-image-api-version 2 image-list'
314+
glance_shell = openstack_shell.OpenStackImagesShell()
315+
self.assertRaises(exc.CommandError, glance_shell.main, args.split())
316+
317+
@mock.patch('glanceclient.v1.client.Client')
318+
def test_auth_plugin_invocation_without_auth_url_with_v1(self, v1_client):
319+
self.make_env(exclude='OS_AUTH_URL')
320+
args = 'image-list'
321+
glance_shell = openstack_shell.OpenStackImagesShell()
322+
self.assertRaises(exc.CommandError, glance_shell.main, args.split())
323+
324+
@mock.patch('glanceclient.v2.client.Client')
325+
def test_auth_plugin_invocation_without_auth_url_with_v2(self, v2_client):
326+
self.make_env(exclude='OS_AUTH_URL')
327+
args = '--os-image-api-version 2 image-list'
328+
glance_shell = openstack_shell.OpenStackImagesShell()
329+
self.assertRaises(exc.CommandError, glance_shell.main, args.split())
330+
331+
@mock.patch('glanceclient.v1.client.Client')
332+
def test_auth_plugin_invocation_without_tenant_with_v1(self, v1_client):
333+
if 'OS_TENANT_NAME' in os.environ:
334+
self.make_env(exclude='OS_TENANT_NAME')
335+
if 'OS_PROJECT_ID' in os.environ:
336+
self.make_env(exclude='OS_PROJECT_ID')
337+
args = 'image-list'
338+
glance_shell = openstack_shell.OpenStackImagesShell()
339+
self.assertRaises(exc.CommandError, glance_shell.main, args.split())
340+
341+
@mock.patch('glanceclient.v2.client.Client')
342+
def test_auth_plugin_invocation_without_tenant_with_v2(self, v2_client):
343+
if 'OS_TENANT_NAME' in os.environ:
344+
self.make_env(exclude='OS_TENANT_NAME')
345+
if 'OS_PROJECT_ID' in os.environ:
346+
self.make_env(exclude='OS_PROJECT_ID')
347+
args = '--os-image-api-version 2 image-list'
348+
glance_shell = openstack_shell.OpenStackImagesShell()
349+
self.assertRaises(exc.CommandError, glance_shell.main, args.split())
350+
303351

304352
class ShellTestWithKeystoneV3Auth(ShellTest):
305353
# auth environment to use

0 commit comments

Comments
 (0)