summaryrefslogtreecommitdiff
path: root/glanceclient/tests
diff options
context:
space:
mode:
authorIan Cordasco <graffatcolmingov@gmail.com>2016-12-07 15:39:22 -0600
committerIan Cordasco <graffatcolmingov@gmail.com>2017-01-11 07:33:34 -0600
commit81039a1e36dd8d85b14f0753bf6d4de14eaeeb94 (patch)
tree383cbad6bc2fa4f3705f21c4c59edb046a387d26 /glanceclient/tests
parent611401d229c38ac2dc5e24d6498678f10910972f (diff)
downloadpython-glanceclient-81039a1e36dd8d85b14f0753bf6d4de14eaeeb94.tar.gz
Handle formatting of subcommand name in error output
On Python 2, decoding all arguments leads to the possibility that users that use the wrong command or mistype the name will see error output with a unicode string's representation instead of one without it. To avoid this we try and find the first non-option string in the argument list and replace it with an string that is not text only on Python 2. If we encoded the string at all times, then users installing glanceclient on Python 3 would see b'invalid-subcommand' instead. That's as bad as seeing u'invalid-subcommand' on Python 2. Closes-bug: 1533090 Change-Id: I018769e159a607ebb233902cbeb13b95ca417190
Diffstat (limited to 'glanceclient/tests')
-rw-r--r--glanceclient/tests/unit/test_shell.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/glanceclient/tests/unit/test_shell.py b/glanceclient/tests/unit/test_shell.py
index d175852..5e59be1 100644
--- a/glanceclient/tests/unit/test_shell.py
+++ b/glanceclient/tests/unit/test_shell.py
@@ -163,6 +163,35 @@ class ShellTest(testutils.TestCase):
sys.stderr = orig_stderr
return (stdout, stderr)
+ def test_fixup_subcommand(self):
+ arglist = [u'image-list', u'--help']
+ if six.PY2:
+ expected_arglist = [b'image-list', u'--help']
+ elif six.PY3:
+ expected_arglist = [u'image-list', u'--help']
+
+ openstack_shell.OpenStackImagesShell._fixup_subcommand(
+ arglist, arglist
+ )
+ self.assertEqual(expected_arglist, arglist)
+
+ def test_fixup_subcommand_with_options_preceding(self):
+ arglist = [u'--os-auth-token', u'abcdef', u'image-list', u'--help']
+ unknown = arglist[2:]
+ if six.PY2:
+ expected_arglist = [
+ u'--os-auth-token', u'abcdef', b'image-list', u'--help'
+ ]
+ elif six.PY3:
+ expected_arglist = [
+ u'--os-auth-token', u'abcdef', u'image-list', u'--help'
+ ]
+
+ openstack_shell.OpenStackImagesShell._fixup_subcommand(
+ unknown, arglist
+ )
+ self.assertEqual(expected_arglist, arglist)
+
def test_help_unknown_command(self):
shell = openstack_shell.OpenStackImagesShell()
argstr = '--os-image-api-version 2 help foofoo'