🏷️ Add mypy to the GitHub Action for tests and fixed types in the whole project (#655)
Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
This commit is contained in:
@@ -6,7 +6,7 @@ from app.tests.utils.item import create_random_item
|
||||
|
||||
|
||||
def test_create_item(
|
||||
client: TestClient, superuser_token_headers: dict, db: Session
|
||||
client: TestClient, superuser_token_headers: dict[str, str], db: Session
|
||||
) -> None:
|
||||
data = {"title": "Foo", "description": "Fighters"}
|
||||
response = client.post(
|
||||
@@ -23,7 +23,7 @@ def test_create_item(
|
||||
|
||||
|
||||
def test_read_item(
|
||||
client: TestClient, superuser_token_headers: dict, db: Session
|
||||
client: TestClient, superuser_token_headers: dict[str, str], db: Session
|
||||
) -> None:
|
||||
item = create_random_item(db)
|
||||
response = client.get(
|
||||
@@ -39,7 +39,7 @@ def test_read_item(
|
||||
|
||||
|
||||
def test_read_item_not_found(
|
||||
client: TestClient, superuser_token_headers: dict, db: Session
|
||||
client: TestClient, superuser_token_headers: dict[str, str], db: Session
|
||||
) -> None:
|
||||
response = client.get(
|
||||
f"{settings.API_V1_STR}/items/999",
|
||||
@@ -51,7 +51,7 @@ def test_read_item_not_found(
|
||||
|
||||
|
||||
def test_read_item_not_enough_permissions(
|
||||
client: TestClient, normal_user_token_headers: dict, db: Session
|
||||
client: TestClient, normal_user_token_headers: dict[str, str], db: Session
|
||||
) -> None:
|
||||
item = create_random_item(db)
|
||||
response = client.get(
|
||||
@@ -64,7 +64,7 @@ def test_read_item_not_enough_permissions(
|
||||
|
||||
|
||||
def test_read_items(
|
||||
client: TestClient, superuser_token_headers: dict, db: Session
|
||||
client: TestClient, superuser_token_headers: dict[str, str], db: Session
|
||||
) -> None:
|
||||
create_random_item(db)
|
||||
create_random_item(db)
|
||||
@@ -78,7 +78,7 @@ def test_read_items(
|
||||
|
||||
|
||||
def test_update_item(
|
||||
client: TestClient, superuser_token_headers: dict, db: Session
|
||||
client: TestClient, superuser_token_headers: dict[str, str], db: Session
|
||||
) -> None:
|
||||
item = create_random_item(db)
|
||||
data = {"title": "Updated title", "description": "Updated description"}
|
||||
@@ -96,7 +96,7 @@ def test_update_item(
|
||||
|
||||
|
||||
def test_update_item_not_found(
|
||||
client: TestClient, superuser_token_headers: dict, db: Session
|
||||
client: TestClient, superuser_token_headers: dict[str, str], db: Session
|
||||
) -> None:
|
||||
data = {"title": "Updated title", "description": "Updated description"}
|
||||
response = client.put(
|
||||
@@ -110,7 +110,7 @@ def test_update_item_not_found(
|
||||
|
||||
|
||||
def test_update_item_not_enough_permissions(
|
||||
client: TestClient, normal_user_token_headers: dict, db: Session
|
||||
client: TestClient, normal_user_token_headers: dict[str, str], db: Session
|
||||
) -> None:
|
||||
item = create_random_item(db)
|
||||
data = {"title": "Updated title", "description": "Updated description"}
|
||||
@@ -125,7 +125,7 @@ def test_update_item_not_enough_permissions(
|
||||
|
||||
|
||||
def test_delete_item(
|
||||
client: TestClient, superuser_token_headers: dict, db: Session
|
||||
client: TestClient, superuser_token_headers: dict[str, str], db: Session
|
||||
) -> None:
|
||||
item = create_random_item(db)
|
||||
response = client.delete(
|
||||
@@ -138,7 +138,7 @@ def test_delete_item(
|
||||
|
||||
|
||||
def test_delete_item_not_found(
|
||||
client: TestClient, superuser_token_headers: dict, db: Session
|
||||
client: TestClient, superuser_token_headers: dict[str, str], db: Session
|
||||
) -> None:
|
||||
response = client.delete(
|
||||
f"{settings.API_V1_STR}/items/999",
|
||||
@@ -150,7 +150,7 @@ def test_delete_item_not_found(
|
||||
|
||||
|
||||
def test_delete_item_not_enough_permissions(
|
||||
client: TestClient, normal_user_token_headers: dict, db: Session
|
||||
client: TestClient, normal_user_token_headers: dict[str, str], db: Session
|
||||
) -> None:
|
||||
item = create_random_item(db)
|
||||
response = client.delete(
|
||||
|
@@ -1,7 +1,8 @@
|
||||
from app.utils import generate_password_reset_token
|
||||
from fastapi.testclient import TestClient
|
||||
from pytest_mock import MockerFixture
|
||||
|
||||
from app.core.config import settings
|
||||
from app.utils import generate_password_reset_token
|
||||
|
||||
|
||||
def test_get_access_token(client: TestClient) -> None:
|
||||
@@ -38,7 +39,7 @@ def test_use_access_token(
|
||||
|
||||
|
||||
def test_recovery_password(
|
||||
client: TestClient, normal_user_token_headers: dict[str, str], mocker
|
||||
client: TestClient, normal_user_token_headers: dict[str, str], mocker: MockerFixture
|
||||
) -> None:
|
||||
mocker.patch("app.utils.send_email", return_value=None)
|
||||
mocker.patch("app.core.config.settings.EMAILS_ENABLED", True)
|
||||
|
@@ -1,4 +1,5 @@
|
||||
from fastapi.testclient import TestClient
|
||||
from pytest_mock import MockerFixture
|
||||
from sqlmodel import Session
|
||||
|
||||
from app import crud
|
||||
@@ -30,7 +31,10 @@ def test_get_users_normal_user_me(
|
||||
|
||||
|
||||
def test_create_user_new_email(
|
||||
client: TestClient, superuser_token_headers: dict, db: Session, mocker
|
||||
client: TestClient,
|
||||
superuser_token_headers: dict[str, str],
|
||||
db: Session,
|
||||
mocker: MockerFixture,
|
||||
) -> None:
|
||||
mocker.patch("app.utils.send_email")
|
||||
mocker.patch("app.core.config.settings.EMAILS_ENABLED", True)
|
||||
@@ -50,7 +54,7 @@ def test_create_user_new_email(
|
||||
|
||||
|
||||
def test_get_existing_user(
|
||||
client: TestClient, superuser_token_headers: dict, db: Session
|
||||
client: TestClient, superuser_token_headers: dict[str, str], db: Session
|
||||
) -> None:
|
||||
username = random_email()
|
||||
password = random_lower_string()
|
||||
@@ -107,7 +111,7 @@ def test_get_existing_user_permissions_error(
|
||||
|
||||
|
||||
def test_create_user_existing_username(
|
||||
client: TestClient, superuser_token_headers: dict, db: Session
|
||||
client: TestClient, superuser_token_headers: dict[str, str], db: Session
|
||||
) -> None:
|
||||
username = random_email()
|
||||
# username = email
|
||||
@@ -140,7 +144,7 @@ def test_create_user_by_normal_user(
|
||||
|
||||
|
||||
def test_retrieve_users(
|
||||
client: TestClient, superuser_token_headers: dict, db: Session
|
||||
client: TestClient, superuser_token_headers: dict[str, str], db: Session
|
||||
) -> None:
|
||||
username = random_email()
|
||||
password = random_lower_string()
|
||||
@@ -179,7 +183,7 @@ def test_update_user_me(
|
||||
|
||||
|
||||
def test_update_password_me(
|
||||
client: TestClient, superuser_token_headers: dict, db: Session
|
||||
client: TestClient, superuser_token_headers: dict[str, str], db: Session
|
||||
) -> None:
|
||||
new_password = random_lower_string()
|
||||
data = {
|
||||
@@ -209,7 +213,7 @@ def test_update_password_me(
|
||||
|
||||
|
||||
def test_update_password_me_incorrect_password(
|
||||
client: TestClient, superuser_token_headers: dict, db: Session
|
||||
client: TestClient, superuser_token_headers: dict[str, str], db: Session
|
||||
) -> None:
|
||||
new_password = random_lower_string()
|
||||
data = {"current_password": new_password, "new_password": new_password}
|
||||
@@ -224,7 +228,7 @@ def test_update_password_me_incorrect_password(
|
||||
|
||||
|
||||
def test_update_password_me_same_password_error(
|
||||
client: TestClient, superuser_token_headers: dict, db: Session
|
||||
client: TestClient, superuser_token_headers: dict[str, str], db: Session
|
||||
) -> None:
|
||||
data = {
|
||||
"current_password": settings.FIRST_SUPERUSER_PASSWORD,
|
||||
@@ -242,7 +246,7 @@ def test_update_password_me_same_password_error(
|
||||
)
|
||||
|
||||
|
||||
def test_create_user_open(client: TestClient, mocker) -> None:
|
||||
def test_create_user_open(client: TestClient, mocker: MockerFixture) -> None:
|
||||
mocker.patch("app.core.config.settings.USERS_OPEN_REGISTRATION", True)
|
||||
username = random_email()
|
||||
password = random_lower_string()
|
||||
@@ -258,7 +262,9 @@ def test_create_user_open(client: TestClient, mocker) -> None:
|
||||
assert created_user["full_name"] == full_name
|
||||
|
||||
|
||||
def test_create_user_open_forbidden_error(client: TestClient, mocker) -> None:
|
||||
def test_create_user_open_forbidden_error(
|
||||
client: TestClient, mocker: MockerFixture
|
||||
) -> None:
|
||||
mocker.patch("app.core.config.settings.USERS_OPEN_REGISTRATION", False)
|
||||
username = random_email()
|
||||
password = random_lower_string()
|
||||
@@ -272,7 +278,9 @@ def test_create_user_open_forbidden_error(client: TestClient, mocker) -> None:
|
||||
assert r.json()["detail"] == "Open user registration is forbidden on this server"
|
||||
|
||||
|
||||
def test_create_user_open_already_exists_error(client: TestClient, mocker) -> None:
|
||||
def test_create_user_open_already_exists_error(
|
||||
client: TestClient, mocker: MockerFixture
|
||||
) -> None:
|
||||
mocker.patch("app.core.config.settings.USERS_OPEN_REGISTRATION", True)
|
||||
password = random_lower_string()
|
||||
full_name = random_lower_string()
|
||||
@@ -382,6 +390,7 @@ def test_delete_user_current_super_user_error(
|
||||
client: TestClient, superuser_token_headers: dict[str, str], db: Session
|
||||
) -> None:
|
||||
super_user = crud.get_user_by_email(session=db, email=settings.FIRST_SUPERUSER)
|
||||
assert super_user
|
||||
user_id = super_user.id
|
||||
|
||||
r = client.delete(
|
||||
|
Reference in New Issue
Block a user