Skip to content

Commit

Permalink
Preserve JSON response data even when there is a failure
Browse files Browse the repository at this point in the history
Otherwise tests that provide data for subsequent tests that are
marked xfail for minor problems would not have their data
available.
  • Loading branch information
cdent committed Feb 11, 2015
1 parent 89ae0c4 commit 1931784
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
2 changes: 1 addition & 1 deletion gabbi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@
# under the License.
"""See gabbi.driver and gabbbi.case."""

__version__ = '0.7.0'
__version__ = '0.7.1'
10 changes: 7 additions & 3 deletions gabbi/case.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,12 @@ def _assert_response(self, response, content, status, headers=None,
expected=None, json_paths=None):
"""Compare the response with expected data."""

# Decode and store response before anything else
decoded_output = self._decode_content(response, content)
if (decoded_output
and 'application/json' in response.get('content-type', '')):
self.json_data = json.loads(decoded_output)

# Never accept a 500
if response['status'] == '500':
raise ServerError(content)
Expand All @@ -105,10 +111,8 @@ def _assert_response(self, response, content, status, headers=None,

# Decode body as JSON and test against json_paths
if json_paths:
response_data = json.loads(decoded_output)
self.json_data = response_data
for path in json_paths:
match = self._extract_json_path_value(response_data, path)
match = self._extract_json_path_value(self.json_data, path)
expected = self._replace_response_values(json_paths[path])
self.assertEqual(expected, match, 'Unable to match %s as %s'
% (path, expected))
Expand Down

0 comments on commit 1931784

Please sign in to comment.