pythonasyncioapiasyncfastapiframeworkjsonjson-schemaopenapiopenapi3pydanticpython-typespython3redocreststarletteswaggerswagger-uiuvicornweb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
26 lines
717 B
26 lines
717 B
import random
|
|
import string
|
|
|
|
from fastapi.testclient import TestClient
|
|
|
|
from app.core.config import settings
|
|
|
|
|
|
def random_lower_string() -> str:
|
|
return "".join(random.choices(string.ascii_lowercase, k=32))
|
|
|
|
|
|
def random_email() -> str:
|
|
return f"{random_lower_string()}@{random_lower_string()}.com"
|
|
|
|
|
|
def get_superuser_token_headers(client: TestClient) -> dict[str, str]:
|
|
login_data = {
|
|
"username": settings.FIRST_SUPERUSER,
|
|
"password": settings.FIRST_SUPERUSER_PASSWORD,
|
|
}
|
|
r = client.post(f"{settings.API_V1_STR}/login/access-token", data=login_data)
|
|
tokens = r.json()
|
|
a_token = tokens["access_token"]
|
|
headers = {"Authorization": f"Bearer {a_token}"}
|
|
return headers
|
|
|