2019-02-09 19:42:36 +04:00
|
|
|
import random
|
|
|
|
import string
|
|
|
|
|
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
|
|
|
|
|
|
|
|
:recycle: Refactor backend, settings, DB sessions, types, configs, plugins (#158)
* :recycle: Refactor backend, update DB session handling
* :sparkles: Add mypy config and plugins
* :heavy_plus_sign: Use Python-jose instead of PyJWT
as it has some extra functionalities and features
* :sparkles: Add/update scripts for test, lint, format
* :wrench: Update lint and format configs
* :art: Update import format, comments, and types
* :art: Add types to config
* :sparkles: Add types for all the code, and small fixes
* :art: Use global imports to simplify exploring with Jupyter
* :recycle: Import schemas and models, instead of each class
* :truck: Rename db_session to db for simplicity
* :pushpin: Update dependencies installation for testing
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))
|
|
|
|
|
|
|
|
|
:recycle: Refactor backend, settings, DB sessions, types, configs, plugins (#158)
* :recycle: Refactor backend, update DB session handling
* :sparkles: Add mypy config and plugins
* :heavy_plus_sign: Use Python-jose instead of PyJWT
as it has some extra functionalities and features
* :sparkles: Add/update scripts for test, lint, format
* :wrench: Update lint and format configs
* :art: Update import format, comments, and types
* :art: Add types to config
* :sparkles: Add types for all the code, and small fixes
* :art: Use global imports to simplify exploring with Jupyter
* :recycle: Import schemas and models, instead of each class
* :truck: Rename db_session to db for simplicity
* :pushpin: Update dependencies installation for testing
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"
|
|
|
|
|
|
|
|
|
2024-02-25 19:39:33 +01: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
|