def _assert_method_raises_dcos_exception_for_json_parse_errors(invoke_method):
def assert_test_case(non_json):
mock_response = mock.create_autospec(requests.Response)
mock_response.json.side_effect = Exception()
mock_response.text = non_json
marathon_client, rpc_client = _create_fixtures()
rpc_client.http_req.return_value = mock_response
with pytest.raises(DCOSException) as exception_info:
invoke_method(marathon_client)
pattern = ('Error: Response from Marathon was not in expected JSON '
'format:\n(.*)')
actual_error = str(exception_info.value)
_assert_matches_with_groups(pattern, actual_error, (non_json,))
assert_test_case('not-json')
assert_test_case('{"oops"}')
评论列表
文章目录