def test_can_encode_binary_json(sample_app): sample_app.api.binary_types.extend(['application/json']) response = app.Response(status_code=200, body={'foo': 'bar'}, headers={'Content-Type': 'application/json'}) encoded_response = response.to_dict(sample_app.api.binary_types) assert encoded_response['body'] == 'eyJmb28iOiAiYmFyIn0='
def test_can_encode_binary_body_with_header_charset(sample_app): response = app.Response( status_code=200, body=b'foobar', headers={'Content-Type': 'application/octet-stream; charset=binary'}) encoded_response = response.to_dict(sample_app.api.binary_types) assert encoded_response['body'] == 'Zm9vYmFy'
def test_invalid_binary_response_body_throws_value_error(sample_app): response = app.Response( status_code=200, body={'foo': 'bar'}, headers={'Content-Type': 'application/octet-stream'}) with pytest.raises(ValueError): response.to_dict(sample_app.api.binary_types)
def test_can_return_unicode_body(sample_app): unicode_data = u'\u2713' response = app.Response( status_code=200, body=unicode_data ) encoded_response = response.to_dict() assert encoded_response['body'] == unicode_data
def bincat(): return app.Response( status_code=200, body=b'\u2713', headers={'Content-Type': content_type})
def bincat(): raw_body = demo.current_request.raw_body return app.Response( raw_body, headers={'Content-Type': content_type}, status_code=200)
def index_view(): return app.Response( status_code=200, body='Plain text', headers={'Content-Type': 'text/plain'})
def index_view(): return app.Response( status_code=200, body=b'\u2713', headers={'Content-Type': 'application/octet-stream'})
def index_view(): return app.Response( status_code=200, body='{}', headers={})
def index_view(): return app.Response( status_code=200, body='{}', headers={'Invalid-Header': 'foo\nbar'})
def index_view(): return app.Response(status_code=200, body={'foo': 'bar'}, headers={'Content-Type': 'application/json'})