Add test case for CLI user-friendly usage / help strings.
@@ -49,6 +49,49 @@ class TestShell(base.BaseCLITestCase):
super(TestShell, self).__init__(*args, **kwargs)
self.shell = Shell()
+ def test_commands_usage_and_help_strings(self):
+ # No command, should print out user friendly usage / help string
+ self.assertEqual(self.shell.run([]), 0)
+
+ self.stdout.seek(0)
+ stdout = self.stdout.read()
+ self.assertTrue('Usage: ' in stdout)
+ self.assertTrue('For example:' in stdout)
+ self.assertTrue('CLI for StackStorm' in stdout)
+ self.assertTrue('positional arguments:' in stdout)
+
+ self.stdout.truncate()
+ self.stderr.truncate()
+
+ # --help should result in the same output
+ try:
+ self.assertEqual(self.shell.run(['--help']), 0)
+ except SystemExit as e:
+ self.assertEqual(e.code, 0)
+
+ self.stdout.seek(0)
+ stdout = self.stdout.read()
+ self.assertTrue('Usage: ' in stdout)
+ self.assertTrue('For example:' in stdout)
+ self.assertTrue('CLI for StackStorm' in stdout)
+ self.assertTrue('positional arguments:' in stdout)
+
+ self.stdout.truncate()
+ self.stderr.truncate()
+
+ # Sub command with no args
+ try:
+ self.assertEqual(self.shell.run(['action']), 2)
+ except SystemExit as e:
+ self.assertEqual(e.code, 2)
+
+ self.stderr.seek(0)
+ stderr = self.stderr.read()
+
+ self.assertTrue('usage' in stderr)
+ self.assertTrue('{list,get,create,update' in stderr)
+ self.assertTrue('error: too few arguments' in stderr)
+
def test_endpoints_default(self):
base_url = 'http://127.0.0.1'
auth_url = 'http://127.0.0.1:9100'
