Exemplo n.º 1
0
def test_respond_json(app_, data):
    with app_.test_request_context(
            headers={'Accept': 'application/json, */*;q=0.5'}):
        assert flask.request.accept_mimetypes
        response = respond(data, 'test.html')
        assert response.mimetype == 'application/json'
        assert data == json.loads(response.data)
Exemplo n.º 2
0
def test_respond_json_array_should_fail(app_):
    with app_.test_request_context(headers={'Accept': 'application/json'}):
        assert flask.request.accept_mimetypes
        with pytest.raises(ValueError):
            respond([1, 2, 3], 'test.html')
Exemplo n.º 3
0
def test_respond_default_to_html(app_, data):
    with app_.test_request_context():
        assert not flask.request.accept_mimetypes
        response = respond(data, 'test.html')
        assert response.mimetype == 'text/html'
        assert 'response: {0}'.format(flask.escape(data)) == response.data