summaryrefslogtreecommitdiff
path: root/functionaltests
diff options
context:
space:
mode:
authorSteve Heyman <steve.heyman@rackspace.com>2015-04-18 11:04:12 -0500
committerSteve Heyman <steve.heyman@rackspace.com>2015-04-27 12:44:21 -0500
commit88c9bfb125d503c052ac44363af160fd24ce107a (patch)
tree2bdbb95b3f68167a5ce4fc3a5162a55f9611edcd /functionaltests
parent8083923114bdb964b3dc65c3e89f0aa51717cf66 (diff)
downloadpython-barbicanclient-88c9bfb125d503c052ac44363af160fd24ce107a.tar.gz
Update stdout and stderr capture in functional tests
Updated base code to correctly capture stderr and stdout for barbican CLI. Change-Id: I75b253a8618531218b0c17aeae45a826c12b47f9
Diffstat (limited to 'functionaltests')
-rw-r--r--functionaltests/cli/base.py25
-rw-r--r--functionaltests/cli/v1/smoke/test_help.py6
2 files changed, 21 insertions, 10 deletions
diff --git a/functionaltests/cli/base.py b/functionaltests/cli/base.py
index 45fb377..2c2ffe2 100644
--- a/functionaltests/cli/base.py
+++ b/functionaltests/cli/base.py
@@ -15,6 +15,7 @@ limitations under the License.
"""
import exceptions as exc
+import six
from functionaltests.base import BaseTestCase
from barbicanclient import barbican
@@ -31,16 +32,26 @@ class CmdLineTestCase(BaseTestCase):
def issue_barbican_command(self, argv):
""" Issue the barbican command and return its output.
+ The barbican command sometimes raises SystemExit, but not always, so
+ we will handle either situation here.
+
+ Also we will create new stdout/stderr streams for each command so that
+ any output from a previous command doesn't contaminate the new command.
+
:param argv: dict of keyword arguments to pass to the command. This
does NOT include "barbican" - that's not needed.
- :return: list of strings returned by the command, one list element
- per line of output. This means the caller doesn't have to worry about
- parsing newlines, etc. If there is a problem then this method
- will return None
+ :return: Two strings - one the captured stdout and one the captured
+ stderr.
"""
- result = None
+
try:
+ self.cmdline_client.stdout = six.StringIO()
+ self.cmdline_client.stderr = six.StringIO()
self.cmdline_client.run(argv)
except exc.SystemExit:
- result = self.cmdline_client.stdout.getvalue()
- return result
+ pass
+
+ outstr = self.cmdline_client.stdout.getvalue()
+ errstr = self.cmdline_client.stderr.getvalue()
+
+ return outstr, errstr
diff --git a/functionaltests/cli/v1/smoke/test_help.py b/functionaltests/cli/v1/smoke/test_help.py
index fc9dc7d..b7b7e21 100644
--- a/functionaltests/cli/v1/smoke/test_help.py
+++ b/functionaltests/cli/v1/smoke/test_help.py
@@ -33,6 +33,6 @@ class HelpTestCase(CmdLineTestCase):
})
@testcase.attr('positive')
def test_help(self, argv):
- result = self.issue_barbican_command(argv)
- self.assertIsNotNone(result, "{0} returned None".format(argv))
- self.assertGreater(len(result), 0, "{0} invalid length".format(argv))
+ stdout, stderr = self.issue_barbican_command(argv)
+ self.assertIsNotNone(stdout, "{0} returned None".format(argv))
+ self.assertGreater(len(stdout), 0, "{0} invalid length".format(argv))