Beispiel #1
0
async def test_response_make_conditional() -> None:
    response = Response(b"abcdef")
    await response.make_conditional(Range("bytes", [RangeSet(0, 3)]))
    assert b"abc" == (await response.get_data())  # type: ignore
    assert response.status_code == 206
    assert response.accept_ranges == "bytes"
    assert response.content_range == ContentRange("bytes", 0, 2, 6)
Beispiel #2
0
async def test_response_make_conditional() -> None:
    response = Response(b"abcdef")
    await response.make_conditional(Range("bytes", [(0, 3)]))
    assert b"abc" == (await response.get_data())  # type: ignore
    assert response.status_code == 206
    assert response.accept_ranges == "bytes"
    assert response.content_range.units == "bytes"
    assert response.content_range.start == 0
    assert response.content_range.stop == 2
    assert response.content_range.length == 6
Beispiel #3
0
def test_response_status(status: Any, expected: int) -> None:
    response = Response(b"Body", status=status)
    assert response.status_code == expected
Beispiel #4
0
def test_datetime_headers(header: str, value: datetime) -> None:
    response = Response(b"Body")
    value = value.replace(microsecond=0)
    setattr(response, header, value)
    assert response.headers.get(header.title().replace("_", "-"))
    assert getattr(response, header) == value
Beispiel #5
0
def test_response_cache_control() -> None:
    response = Response(b"Body")
    response.cache_control.max_age = 2
    assert response.headers["Cache-Control"] == "max-age=2"
    response.cache_control.no_cache = True
    assert response.headers["Cache-Control"] == "max-age=2, no-cache"
Beispiel #6
0
async def test_response_make_conditional_not_satisfiable(
        range_: Range) -> None:
    response = Response(b"abcdef")
    with pytest.raises(RequestRangeNotSatisfiable):
        await response.make_conditional(range_)
Beispiel #7
0
async def test_response_make_conditional_no_condition(range_: Range) -> None:
    response = Response(b"abcdef")
    await response.make_conditional(range_)
    assert b"abcdef" == (await response.get_data())  # type: ignore
    assert response.status_code == 200
    assert response.accept_ranges == "bytes"
Beispiel #8
0
async def test_response_body() -> None:
    response = Response(b"Body")
    assert b"Body" == (await response.get_data())  # type: ignore
    # Fetch again to ensure it isn't exhausted
    assert b"Body" == (await response.get_data())  # type: ignore
Beispiel #9
0
def test_response_status_error() -> None:
    with pytest.raises(ValueError) as error_info:
        Response(b"Body", "200 OK")
    assert str(error_info.value
               ) == "Quart  does not support non-integer status values"
Beispiel #10
0
def test_response_cache_control() -> None:
    response = Response(b'Body')
    response.cache_control.max_age = 2
    assert response.headers['Cache-Control'] == 'max-age=2'
    response.cache_control.no_cache = True
    assert response.headers['Cache-Control'] == 'max-age=2,no-cache'
Beispiel #11
0
def jsonify_response(json, resp_code=200):
    return Response(dumps(json), resp_code, mimetype="application/json")