🎨 Format files with pre-commit and Ruff (#611)

This commit is contained in:
Sebastián Ramírez
2024-02-25 19:39:33 +01:00
committed by GitHub
parent 2802a4df9e
commit 0cc802eec8
35 changed files with 156 additions and 163 deletions

View File

@@ -1,12 +1,10 @@
from typing import Dict
from fastapi.testclient import TestClient
from app.core.config import settings
def test_celery_worker_test(
client: TestClient, superuser_token_headers: Dict[str, str]
client: TestClient, superuser_token_headers: dict[str, str]
) -> None:
data = {"message": "test"}
r = client.post(

View File

@@ -10,7 +10,9 @@ def test_create_item(
) -> None:
data = {"title": "Foo", "description": "Fighters"}
response = client.post(
f"{settings.API_V1_STR}/items/", headers=superuser_token_headers, json=data,
f"{settings.API_V1_STR}/items/",
headers=superuser_token_headers,
json=data,
)
assert response.status_code == 200
content = response.json()
@@ -25,7 +27,8 @@ def test_read_item(
) -> None:
item = create_random_item(db)
response = client.get(
f"{settings.API_V1_STR}/items/{item.id}", headers=superuser_token_headers,
f"{settings.API_V1_STR}/items/{item.id}",
headers=superuser_token_headers,
)
assert response.status_code == 200
content = response.json()

View File

@@ -1,5 +1,3 @@
from typing import Dict
from fastapi.testclient import TestClient
from app.core.config import settings
@@ -18,10 +16,11 @@ def test_get_access_token(client: TestClient) -> None:
def test_use_access_token(
client: TestClient, superuser_token_headers: Dict[str, str]
client: TestClient, superuser_token_headers: dict[str, str]
) -> None:
r = client.post(
f"{settings.API_V1_STR}/login/test-token", headers=superuser_token_headers,
f"{settings.API_V1_STR}/login/test-token",
headers=superuser_token_headers,
)
result = r.json()
assert r.status_code == 200

View File

@@ -1,5 +1,3 @@
from typing import Dict
from fastapi.testclient import TestClient
from sqlalchemy.orm import Session
@@ -10,7 +8,7 @@ from app.tests.utils.utils import random_email, random_lower_string
def test_get_users_superuser_me(
client: TestClient, superuser_token_headers: Dict[str, str]
client: TestClient, superuser_token_headers: dict[str, str]
) -> None:
r = client.get(f"{settings.API_V1_STR}/users/me", headers=superuser_token_headers)
current_user = r.json()
@@ -21,7 +19,7 @@ def test_get_users_superuser_me(
def test_get_users_normal_user_me(
client: TestClient, normal_user_token_headers: Dict[str, str]
client: TestClient, normal_user_token_headers: dict[str, str]
) -> None:
r = client.get(f"{settings.API_V1_STR}/users/me", headers=normal_user_token_headers)
current_user = r.json()
@@ -38,7 +36,9 @@ def test_create_user_new_email(
password = random_lower_string()
data = {"email": username, "password": password}
r = client.post(
f"{settings.API_V1_STR}/users/", headers=superuser_token_headers, json=data,
f"{settings.API_V1_STR}/users/",
headers=superuser_token_headers,
json=data,
)
assert 200 <= r.status_code < 300
created_user = r.json()
@@ -56,7 +56,8 @@ def test_get_existing_user(
user = crud.user.create(db, obj_in=user_in)
user_id = user.id
r = client.get(
f"{settings.API_V1_STR}/users/{user_id}", headers=superuser_token_headers,
f"{settings.API_V1_STR}/users/{user_id}",
headers=superuser_token_headers,
)
assert 200 <= r.status_code < 300
api_user = r.json()
@@ -75,7 +76,9 @@ def test_create_user_existing_username(
crud.user.create(db, obj_in=user_in)
data = {"email": username, "password": password}
r = client.post(
f"{settings.API_V1_STR}/users/", headers=superuser_token_headers, json=data,
f"{settings.API_V1_STR}/users/",
headers=superuser_token_headers,
json=data,
)
created_user = r.json()
assert r.status_code == 400
@@ -83,13 +86,15 @@ def test_create_user_existing_username(
def test_create_user_by_normal_user(
client: TestClient, normal_user_token_headers: Dict[str, str]
client: TestClient, normal_user_token_headers: dict[str, str]
) -> None:
username = random_email()
password = random_lower_string()
data = {"email": username, "password": password}
r = client.post(
f"{settings.API_V1_STR}/users/", headers=normal_user_token_headers, json=data,
f"{settings.API_V1_STR}/users/",
headers=normal_user_token_headers,
json=data,
)
assert r.status_code == 400

View File

@@ -1,4 +1,4 @@
from typing import Dict, Generator
from collections.abc import Generator
import pytest
from fastapi.testclient import TestClient
@@ -24,12 +24,12 @@ def client() -> Generator:
@pytest.fixture(scope="module")
def superuser_token_headers(client: TestClient) -> Dict[str, str]:
def superuser_token_headers(client: TestClient) -> dict[str, str]:
return get_superuser_token_headers(client)
@pytest.fixture(scope="module")
def normal_user_token_headers(client: TestClient, db: Session) -> Dict[str, str]:
def normal_user_token_headers(client: TestClient, db: Session) -> dict[str, str]:
return authentication_token_from_email(
client=client, email=settings.EMAIL_TEST_USER, db=db
)

View File

@@ -1,5 +1,3 @@
from typing import Optional
from sqlalchemy.orm import Session
from app import crud, models
@@ -8,7 +6,7 @@ from app.tests.utils.user import create_random_user
from app.tests.utils.utils import random_lower_string
def create_random_item(db: Session, *, owner_id: Optional[int] = None) -> models.Item:
def create_random_item(db: Session, *, owner_id: int | None = None) -> models.Item:
if owner_id is None:
user = create_random_user(db)
owner_id = user.id

View File

@@ -1,5 +1,3 @@
from typing import Dict
from fastapi.testclient import TestClient
from sqlalchemy.orm import Session
@@ -12,7 +10,7 @@ from app.tests.utils.utils import random_email, random_lower_string
def user_authentication_headers(
*, client: TestClient, email: str, password: str
) -> Dict[str, str]:
) -> dict[str, str]:
data = {"username": email, "password": password}
r = client.post(f"{settings.API_V1_STR}/login/access-token", data=data)
@@ -32,7 +30,7 @@ def create_random_user(db: Session) -> User:
def authentication_token_from_email(
*, client: TestClient, email: str, db: Session
) -> Dict[str, str]:
) -> dict[str, str]:
"""
Return a valid token for the user with given email.

View File

@@ -1,6 +1,5 @@
import random
import string
from typing import Dict
from fastapi.testclient import TestClient
@@ -15,7 +14,7 @@ def random_email() -> str:
return f"{random_lower_string()}@{random_lower_string()}.com"
def get_superuser_token_headers(client: TestClient) -> Dict[str, str]:
def get_superuser_token_headers(client: TestClient) -> dict[str, str]:
login_data = {
"username": settings.FIRST_SUPERUSER,
"password": settings.FIRST_SUPERUSER_PASSWORD,