Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ jobs:
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
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ classifiers = [
"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",
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import pytest
from fastapi.testclient import TestClient

from ...utils import skip_py36
from ...utils import needs_py37

openapi_schema = {
"openapi": "3.0.2",
Expand Down Expand Up @@ -340,14 +340,14 @@ def client():
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": "[email protected]", "password": "secret"}
response = client.post("/users/", json=test_user)
Expand All @@ -359,7 +359,7 @@ def test_create_user(client):
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
Expand All @@ -368,13 +368,13 @@ def test_get_user(client):
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
Expand All @@ -386,7 +386,7 @@ def test_get_users(client):
time.sleep = MagicMock()


@skip_py36
@needs_py37
def test_get_slowusers(client):
response = client.get("/slowusers/")
assert response.status_code == 200, response.text
Expand All @@ -395,7 +395,7 @@ def test_get_slowusers(client):
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)
Expand All @@ -419,7 +419,7 @@ def test_create_item(client):
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
Expand Down
24 changes: 24 additions & 0 deletions tests/test_typing_python39.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
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
8 changes: 4 additions & 4 deletions tests/test_union_inherited_body.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
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
Expand Down Expand Up @@ -118,21 +118,21 @@ def save_union_different_body(item: Union[ExtendedItem, 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
Expand Down
3 changes: 2 additions & 1 deletion tests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@

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+")