Add verbose option for stdout in subunit_describe_call
The PS will allow request and response header and body data to be printed to stdout when the -v or --verbose switch is given. Change-Id: Ibc3ac0ee717e6f71e74fd5970877a7eda89be3a7 Closes-bug: #1749238
This commit is contained in:
parent
c25801a985
commit
8b3dc8619b
@ -29,6 +29,9 @@ Runtime Arguments
|
||||
written to. This contains more information than is present in stdout.
|
||||
* ``--ports, -p``: (Optional) The path to a JSON file describing the ports
|
||||
being used by different services
|
||||
* ``--verbose, -v``: (Optional) Print Request and Response Headers and Body
|
||||
data to stdout
|
||||
|
||||
|
||||
Usage
|
||||
-----
|
||||
@ -262,6 +265,10 @@ class ArgumentParser(argparse.ArgumentParser):
|
||||
"-p", "--ports", metavar="<ports file>", default=None,
|
||||
help="A JSON file describing the ports for each service.")
|
||||
|
||||
self.add_argument(
|
||||
"-v", "--verbose", action='store_true', default=False,
|
||||
help="Add Request and Response header and body data to stdout.")
|
||||
|
||||
|
||||
def parse(stream, non_subunit_name, ports):
|
||||
if ports is not None and os.path.exists(ports):
|
||||
@ -286,7 +293,7 @@ def parse(stream, non_subunit_name, ports):
|
||||
return url_parser
|
||||
|
||||
|
||||
def output(url_parser, output_file):
|
||||
def output(url_parser, output_file, verbose):
|
||||
if output_file is not None:
|
||||
with open(output_file, "w") as outfile:
|
||||
outfile.write(json.dumps(url_parser.test_logs))
|
||||
@ -302,13 +309,22 @@ def output(url_parser, output_file):
|
||||
sys.stdout.write('\t- {0} {1} request for {2} to {3}\n'.format(
|
||||
item.get('status_code'), item.get('verb'),
|
||||
item.get('service'), item.get('url')))
|
||||
if verbose:
|
||||
sys.stdout.write('\t\t- request headers: {0}\n'.format(
|
||||
item.get('request_headers')))
|
||||
sys.stdout.write('\t\t- request body: {0}\n'.format(
|
||||
item.get('request_body')))
|
||||
sys.stdout.write('\t\t- response headers: {0}\n'.format(
|
||||
item.get('response_headers')))
|
||||
sys.stdout.write('\t\t- response body: {0}\n'.format(
|
||||
item.get('response_body')))
|
||||
sys.stdout.write('\n')
|
||||
|
||||
|
||||
def entry_point():
|
||||
cl_args = ArgumentParser().parse_args()
|
||||
parser = parse(cl_args.subunit, cl_args.non_subunit_name, cl_args.ports)
|
||||
output(parser, cl_args.output_file)
|
||||
output(parser, cl_args.output_file, cl_args.verbose)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
@ -33,15 +33,42 @@ class TestSubunitDescribeCalls(base.TestCase):
|
||||
p.communicate()
|
||||
self.assertEqual(0, p.returncode)
|
||||
|
||||
def test_verbose(self):
|
||||
subunit_file = os.path.join(
|
||||
os.path.dirname(os.path.abspath(__file__)),
|
||||
'sample_streams/calls.subunit')
|
||||
p = subprocess.Popen([
|
||||
'subunit-describe-calls', '-s', subunit_file,
|
||||
'-v'], stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||
stdout = p.communicate()
|
||||
self.assertEqual(0, p.returncode)
|
||||
self.assertIn(b'- request headers:', stdout[0])
|
||||
self.assertIn(b'- request body:', stdout[0])
|
||||
self.assertIn(b'- response headers:', stdout[0])
|
||||
self.assertIn(b'- response body:', stdout[0])
|
||||
|
||||
def test_return_code_no_output(self):
|
||||
subunit_file = os.path.join(
|
||||
os.path.dirname(os.path.abspath(__file__)),
|
||||
'sample_streams/calls.subunit')
|
||||
p = subprocess.Popen([
|
||||
'subunit-describe-calls', '-s', subunit_file],
|
||||
stdin=subprocess.PIPE)
|
||||
p.communicate()
|
||||
stdin=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||
stdout = p.communicate()
|
||||
self.assertEqual(0, p.returncode)
|
||||
self.assertIn(b'foo', stdout[0])
|
||||
self.assertIn(b'- 200 POST request for Nova to v2.1/<id>/',
|
||||
stdout[0])
|
||||
self.assertIn(b'- 200 DELETE request for Nova to v2.1/<id>/',
|
||||
stdout[0])
|
||||
self.assertIn(b'- 200 GET request for Nova to v2.1/<id>/',
|
||||
stdout[0])
|
||||
self.assertIn(b'- 404 DELETE request for Nova to v2.1/<id>/',
|
||||
stdout[0])
|
||||
self.assertNotIn(b'- request headers:', stdout[0])
|
||||
self.assertNotIn(b'- request body:', stdout[0])
|
||||
self.assertNotIn(b'- response headers:', stdout[0])
|
||||
self.assertNotIn(b'- response body:', stdout[0])
|
||||
|
||||
def test_parse(self):
|
||||
subunit_file = os.path.join(
|
||||
|
Loading…
x
Reference in New Issue
Block a user