Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compact JSON representation #958

Merged
merged 1 commit into from
Dec 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion chalice/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,8 @@ def __init__(self, body, headers=None, status_code=200):
def to_dict(self, binary_types=None):
body = self.body
if not isinstance(body, _ANY_STRING):
body = json.dumps(body, default=handle_decimals)
body = json.dumps(body, separators=(',', ':'),
default=handle_decimals)
response = {
'headers': self.headers,
'statusCode': self.status_code,
Expand Down
4 changes: 2 additions & 2 deletions tests/functional/test_local.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ def test_can_accept_get_request(config, sample_app, local_server_factory):
local_server, port = local_server_factory(sample_app, config)
response = local_server.make_call(requests.get, '/', port)
assert response.status_code == 200
assert response.text == '{"hello": "world"}'
assert response.text == '{"hello":"world"}'


def test_can_get_unicode_string_content_length(
Expand Down Expand Up @@ -222,7 +222,7 @@ def test_can_accept_multiple_connections(config, sample_app,
'from going though.'
)
assert response.status_code == 200
assert response.text == '{"hello": "world"}'
assert response.text == '{"hello":"world"}'


def test_can_import_env_vars(unused_tcp_port, http_session):
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def test_can_encode_binary_json(sample_app):
headers={'Content-Type': 'application/json'}
)
encoded_response = response.to_dict(sample_app.api.binary_types)
assert encoded_response['body'] == 'eyJmb28iOiAiYmFyIn0='
assert encoded_response['body'] == 'eyJmb28iOiJiYXIifQ=='


def test_can_parse_route_view_args():
Expand Down Expand Up @@ -510,7 +510,7 @@ def index_view():

event = create_event('/index', 'GET', {})
response = demo(event, context=None)
assert response == {'statusCode': 200, 'body': '{"foo": "bar"}',
assert response == {'statusCode': 200, 'body': '{"foo":"bar"}',
'headers': {'Content-Type': 'application/json'}}


Expand Down