mirror of
https://github.com/kevin-DL/full-stack-fastapi-postgresql.git
synced 2026-01-12 02:05:14 +00:00
* Use Pydantic BaseSettings for config settings * Update fastapi dep to >=0.47.0 and email_validator to email-validator * Fix deprecation warning for Pydantic >=1.0 * Properly support old-format comma separated strings for BACKEND_CORS_ORIGINS Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
36 lines
841 B
Python
36 lines
841 B
Python
import random
|
|
import string
|
|
|
|
import requests
|
|
|
|
from app.core.config import settings
|
|
|
|
|
|
def random_lower_string():
|
|
return "".join(random.choices(string.ascii_lowercase, k=32))
|
|
|
|
|
|
def random_email():
|
|
return f"{random_lower_string()}@{random_lower_string()}.com"
|
|
|
|
|
|
def get_server_api():
|
|
server_name = f"http://{settings.SERVER_NAME}"
|
|
return server_name
|
|
|
|
|
|
def get_superuser_token_headers():
|
|
server_api = get_server_api()
|
|
login_data = {
|
|
"username": settings.FIRST_SUPERUSER,
|
|
"password": settings.FIRST_SUPERUSER_PASSWORD,
|
|
}
|
|
r = requests.post(
|
|
f"{server_api}{settings.API_V1_STR}/login/access-token", data=login_data
|
|
)
|
|
tokens = r.json()
|
|
a_token = tokens["access_token"]
|
|
headers = {"Authorization": f"Bearer {a_token}"}
|
|
# superuser_token_headers = headers
|
|
return headers
|