2019-02-09 19:42:36 +04:00
|
|
|
import random
|
|
|
|
|
import string
|
2020-04-20 19:03:13 +02:00
|
|
|
from typing import Dict
|
2019-02-09 19:42:36 +04:00
|
|
|
|
2020-04-20 20:31:29 +02:00
|
|
|
from fastapi.testclient import TestClient
|
2020-04-16 23:56:10 -06:00
|
|
|
|
|
|
|
|
from app.core.config import settings
|
2019-02-09 19:42:36 +04:00
|
|
|
|
|
|
|
|
|
2020-04-20 19:03:13 +02:00
|
|
|
def random_lower_string() -> str:
|
2019-02-09 19:42:36 +04:00
|
|
|
return "".join(random.choices(string.ascii_lowercase, k=32))
|
|
|
|
|
|
|
|
|
|
|
2020-04-20 19:03:13 +02:00
|
|
|
def random_email() -> str:
|
2020-04-06 11:36:29 +02:00
|
|
|
return f"{random_lower_string()}@{random_lower_string()}.com"
|
|
|
|
|
|
|
|
|
|
|
2020-04-20 20:31:29 +02:00
|
|
|
def get_superuser_token_headers(client: TestClient) -> Dict[str, str]:
|
2019-02-09 19:42:36 +04:00
|
|
|
login_data = {
|
2020-04-16 23:56:10 -06:00
|
|
|
"username": settings.FIRST_SUPERUSER,
|
|
|
|
|
"password": settings.FIRST_SUPERUSER_PASSWORD,
|
2019-02-09 19:42:36 +04:00
|
|
|
}
|
2020-04-20 20:31:29 +02:00
|
|
|
r = client.post(f"{settings.API_V1_STR}/login/access-token", data=login_data)
|
2019-02-09 19:42:36 +04:00
|
|
|
tokens = r.json()
|
|
|
|
|
a_token = tokens["access_token"]
|
|
|
|
|
headers = {"Authorization": f"Bearer {a_token}"}
|
|
|
|
|
return headers
|