File: test_fastapi.py

package info (click to toggle)
python-cross-web 0.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 744 kB
  • sloc: python: 2,262; sh: 23; makefile: 10
file content (35 lines) | stat: -rw-r--r-- 943 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import pytest

from cross_web import Response

pytestmark = [pytest.mark.fastapi]


def test_basic_response() -> None:
    from fastapi import Response as FastAPIResponse

    response = Response(
        body="Hello, world!",
        status_code=200,
        headers={"Content-Type": "text/plain"},
    )

    fastapi_response = response.to_fastapi()

    assert isinstance(fastapi_response, FastAPIResponse)

    assert fastapi_response.status_code == 200
    assert fastapi_response.headers["Content-Type"] == "text/plain"
    assert fastapi_response.body == b"Hello, world!"


def test_redirect() -> None:
    from fastapi import Response as FastAPIResponse

    response = Response.redirect("https://example.com")
    fastapi_response = response.to_fastapi()

    assert isinstance(fastapi_response, FastAPIResponse)

    assert fastapi_response.status_code == 302
    assert fastapi_response.headers["Location"] == "https://example.com"