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.
60 lines
1.4 KiB
60 lines
1.4 KiB
import os
|
|
from typing import Iterator
|
|
from typing import Type
|
|
|
|
import pytest
|
|
import utilities
|
|
from flask.testing import FlaskClient
|
|
from monsun_backend.container import get_initialize_container
|
|
from sqlalchemy import create_engine
|
|
from sqlalchemy_utils import create_database
|
|
from sqlalchemy_utils import database_exists
|
|
from utilities import setup_app
|
|
|
|
|
|
@pytest.fixture(scope="session", autouse=True)
|
|
def db_test():
|
|
"""makes sure that the DB exists"""
|
|
engine = create_engine(os.getenv("DATABASE_URI"))
|
|
if not database_exists(engine.url):
|
|
create_database(engine.url)
|
|
|
|
|
|
@pytest.fixture(scope="class")
|
|
def app_class_scope(db_test):
|
|
with setup_app() as app:
|
|
yield app
|
|
|
|
|
|
@pytest.fixture(scope="class")
|
|
def client_class_scope(app_class_scope):
|
|
return app_class_scope.test_client
|
|
|
|
|
|
@pytest.fixture()
|
|
def app(db_test):
|
|
with setup_app() as app:
|
|
yield app
|
|
|
|
|
|
@pytest.fixture()
|
|
def client(app):
|
|
return app.test_client
|
|
|
|
|
|
@pytest.fixture(scope="class")
|
|
def as_admin(
|
|
client_class_scope: Type[FlaskClient],
|
|
) -> Iterator[utilities.TestUser]:
|
|
container = get_initialize_container()
|
|
with client_class_scope() as client_:
|
|
yield utilities.TestUser(
|
|
client_.post(
|
|
"/login",
|
|
data={
|
|
"email": container.config.admin_user_email(),
|
|
"password": container.config.admin_user_password(),
|
|
},
|
|
),
|
|
client_,
|
|
)
|
|
|