runs-on: ubuntu-latest
strategy:
matrix:
- python-version: [3.6, 3.7, 3.8]
+ python-version: [3.6, 3.7, 3.8, 3.9]
fail-fast: false
-
+
steps:
- uses: actions/checkout@v2
- name: Set up Python
"Programming Language :: Python :: 3.6",
"Programming Language :: Python :: 3.7",
"Programming Language :: Python :: 3.8",
+ "Programming Language :: Python :: 3.9",
"Topic :: Internet :: WWW/HTTP :: HTTP Servers",
"Topic :: Internet :: WWW/HTTP",
]
import pytest
from fastapi.testclient import TestClient
-from ...utils import skip_py36
+from ...utils import needs_py37
openapi_schema = {
"openapi": "3.0.2",
test_db.unlink()
-@skip_py36
+@needs_py37
def test_openapi_schema(client):
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == openapi_schema
-@skip_py36
+@needs_py37
def test_create_user(client):
test_user = {"email": "johndoe@example.com", "password": "secret"}
response = client.post("/users/", json=test_user)
assert response.status_code == 400, response.text
-@skip_py36
+@needs_py37
def test_get_user(client):
response = client.get("/users/1")
assert response.status_code == 200, response.text
assert "id" in data
-@skip_py36
+@needs_py37
def test_inexistent_user(client):
response = client.get("/users/999")
assert response.status_code == 404, response.text
-@skip_py36
+@needs_py37
def test_get_users(client):
response = client.get("/users/")
assert response.status_code == 200, response.text
time.sleep = MagicMock()
-@skip_py36
+@needs_py37
def test_get_slowusers(client):
response = client.get("/slowusers/")
assert response.status_code == 200, response.text
assert "id" in data[0]
-@skip_py36
+@needs_py37
def test_create_item(client):
item = {"title": "Foo", "description": "Something that fights"}
response = client.post("/users/1/items/", json=item)
assert item_to_check["description"] == item["description"]
-@skip_py36
+@needs_py37
def test_read_items(client):
response = client.get("/items/")
assert response.status_code == 200, response.text
--- /dev/null
+from fastapi import FastAPI
+from fastapi.testclient import TestClient
+
+from .utils import needs_py39
+
+
+@needs_py39
+def test_typing():
+ types = {
+ list[int]: [1, 2, 3],
+ dict[str, list[int]]: {"a": [1, 2, 3], "b": [4, 5, 6]},
+ set[int]: [1, 2, 3], # `set` is converted to `list`
+ tuple[int, ...]: [1, 2, 3], # `tuple` is converted to `list`
+ }
+ for test_type, expect in types.items():
+ app = FastAPI()
+
+ @app.post("/", response_model=test_type)
+ def post_endpoint(input: test_type):
+ return input
+
+ res = TestClient(app).post("/", json=expect)
+ assert res.status_code == 200, res.json()
+ assert res.json() == expect
from fastapi.testclient import TestClient
from pydantic import BaseModel
-from .utils import skip_py36
+from .utils import needs_py37
# In Python 3.6:
# u = Union[ExtendedItem, Item] == __main__.Item
}
-@skip_py36
+@needs_py37
def test_inherited_item_openapi_schema():
response = client.get("/openapi.json")
assert response.status_code == 200, response.text
assert response.json() == inherited_item_openapi_schema
-@skip_py36
+@needs_py37
def test_post_extended_item():
response = client.post("/items/", json={"name": "Foo", "age": 5})
assert response.status_code == 200, response.text
assert response.json() == {"item": {"name": "Foo", "age": 5}}
-@skip_py36
+@needs_py37
def test_post_item():
response = client.post("/items/", json={"name": "Foo"})
assert response.status_code == 200, response.text
import pytest
-skip_py36 = pytest.mark.skipif(sys.version_info < (3, 7), reason="skip python3.6")
+needs_py37 = pytest.mark.skipif(sys.version_info < (3, 7), reason="requires python3.7+")
+needs_py39 = pytest.mark.skipif(sys.version_info < (3, 9), reason="requires python3.9+")