예제 #1
0
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='
예제 #2
0
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'
예제 #3
0
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)
예제 #4
0
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
예제 #5
0
 def bincat():
     return app.Response(
         status_code=200,
         body=b'\u2713',
         headers={'Content-Type': content_type})
예제 #6
0
 def bincat():
     raw_body = demo.current_request.raw_body
     return app.Response(
         raw_body,
         headers={'Content-Type': content_type},
         status_code=200)
예제 #7
0
 def index_view():
     return app.Response(
         status_code=200,
         body='Plain text',
         headers={'Content-Type': 'text/plain'})
예제 #8
0
 def index_view():
     return app.Response(
         status_code=200,
         body=b'\u2713',
         headers={'Content-Type': 'application/octet-stream'})
예제 #9
0
 def index_view():
     return app.Response(
         status_code=200, body='{}', headers={})
예제 #10
0
 def index_view():
     return app.Response(
         status_code=200, body='{}',
         headers={'Invalid-Header': 'foo\nbar'})
예제 #11
0
 def index_view():
     return app.Response(status_code=200, body={'foo': 'bar'},
                         headers={'Content-Type': 'application/json'})