Skip to content

Commit

Permalink
Merge pull request #193 from gdb/master
Browse files Browse the repository at this point in the history
Make JSON printing a bit nicer
  • Loading branch information
jmcs committed Apr 5, 2016
2 parents 5e7c946 + a6cc07c commit 40053ac
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion connexion/decorators/produces.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def wrapper(*args, **kwargs):
logger.debug('Endpoint returned an empty response (204)', extra={'url': url, 'mimetype': self.mimetype})
return '', 204, headers

data = json.dumps(data, indent=2)
data = [json.dumps(data, indent=2), '\n']
response = flask.current_app.response_class(data, mimetype=self.mimetype) # type: flask.Response
response = self.process_headers(response, headers)

Expand Down
2 changes: 1 addition & 1 deletion connexion/problem.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ def problem(status, title, detail, type='about:blank', instance=None, headers=No
if ext:
problem_response.update(ext)

body = json.dumps(problem_response)
body = [json.dumps(problem_response, indent=2), '\n']
response = flask.current_app.response_class(body, mimetype='application/problem+json',
status=status) # type: flask.Response
if headers:
Expand Down
4 changes: 2 additions & 2 deletions tests/api/test_bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,13 +100,13 @@ def route2():
def test_resolve_method(simple_app):
app_client = simple_app.app.test_client()
resp = app_client.get('/v1.0/resolver-test/method') # type: flask.Response
assert resp.data.decode() == '"DummyClass"'
assert resp.data.decode() == '"DummyClass"\n'


def test_resolve_classmethod(simple_app):
app_client = simple_app.app.test_client()
resp = app_client.get('/v1.0/resolver-test/classmethod') # type: flask.Response
assert resp.data.decode() == '"DummyClass"'
assert resp.data.decode() == '"DummyClass"\n'


def test_add_api_with_function_resolver_function_is_wrapped(simple_api_spec_dir):
Expand Down
4 changes: 2 additions & 2 deletions tests/api/test_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def test_array_query_param(simple_app):
def test_path_parameter_someint(simple_app):
app_client = simple_app.app.test_client()
resp = app_client.get('/v1.0/test-int-path/123') # type: flask.Response
assert resp.data.decode() == '"int"'
assert resp.data.decode() == '"int"\n'

# non-integer values will not match Flask route
resp = app_client.get('/v1.0/test-int-path/foo') # type: flask.Response
Expand All @@ -66,7 +66,7 @@ def test_path_parameter_someint(simple_app):
def test_path_parameter_somefloat(simple_app):
app_client = simple_app.app.test_client()
resp = app_client.get('/v1.0/test-float-path/123.45') # type: flask.Response
assert resp.data.decode() == '"float"'
assert resp.data.decode() == '"float"\n'

# non-float values will not match Flask route
resp = app_client.get('/v1.0/test-float-path/123,45') # type: flask.Response
Expand Down
2 changes: 1 addition & 1 deletion tests/test_validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def test_parameter_validator(monkeypatch):
request.headers = {}
request.params = {}
app = MagicMock(name='app')
app.response_class = lambda a, mimetype, status: json.loads(a)['detail']
app.response_class = lambda a, mimetype, status: json.loads(''.join(a))['detail']
monkeypatch.setattr('flask.request', request)
monkeypatch.setattr('flask.current_app', app)

Expand Down

0 comments on commit 40053ac

Please sign in to comment.