Skip to content

Commit

Permalink
Make new code work in Python 3
Browse files Browse the repository at this point in the history
  • Loading branch information
Björn Andersson committed Nov 25, 2015
1 parent 986c66d commit a134b08
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
7 changes: 6 additions & 1 deletion gocd/api/response.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,12 @@ def payload(self):
"""
if self.is_json:
if not self._body_parsed:
self._body_parsed = json.loads(self._body.decode('utf-8'))
if hasattr(self._body, 'decode'):
body = self._body.decode('utf-8')
else:
body = self._body

self._body_parsed = json.loads(body)

return self._body_parsed
else:
Expand Down
3 changes: 2 additions & 1 deletion tests/api/test_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ def test_console_output_single_stage(pipeline):
instance = pipeline.instance()
metadata, output = next(pipeline.console_output(instance))

assert r'[go] Job completed' in output
assert r'[go] Job completed' in output.decode('utf8')
assert {'pipeline': 'Simple',
'pipeline_counter': instance['counter'],
'stage': 'defaultStage',
Expand All @@ -231,6 +231,7 @@ def test_console_output_multiple_stages(pipeline_multiple_stages):
valid_args = ['Good Bye', 'Hello', 'ehlo test.somewhere.tld']
valid = 0
for metadata, output in pipeline.console_output():
output = output.decode('utf8')
assert r'[go] Job completed' in output
assert True in (
'<arg>{0}</arg>'.format(job) in output for job in valid_args
Expand Down

0 comments on commit a134b08

Please sign in to comment.