Example #1
0
def test_export_response():
    app = Flask(__name__)
    with app.test_request_context("/"):
        resp = make_response("hello")

        resp = export(resp)
        assert resp.mimetype == "text/html"
        assert resp.status_code == 200
        assert resp.data == b"hello"

        resp = export(resp, 400)
        assert resp.mimetype == "text/html"
        assert resp.status_code == 400
        assert resp.data == b"hello"
Example #2
0
def test_export(rv, code, headers):
    app = Flask(__name__)
    with app.test_request_context("/"):

        resp = export(rv)
        assert resp.status_code == 200

        resp = export(rv, code)
        assert resp.mimetype == "application/json"
        assert resp.status_code == code
        assert resp_json(resp) == rv

        if headers is not None:
            resp = export(rv, None, headers)
            if isinstance(headers, dict):
                for k, v in headers.items():
                    assert resp.headers[k] == v
            else:
                for k, v in headers:
                    assert resp.headers[k] == v
Example #3
0
def test_export_custom():
    app = Flask(__name__)

    @exporter("text/html")
    def export_html(rv, code, headers):
        return make_response(rv, code, headers)

    accept = "text/html,application/xhtml+xml,application/xml;"\
        "q=0.9,image/webp,*/*;q=0.8"
    with app.test_request_context(headers={"Accept": accept}):
        resp = export("hello world")
        assert resp.mimetype == "text/html"
        assert resp.data == b"hello world"