Skip to content

Commit

Permalink
refactor conftest.py
Browse files Browse the repository at this point in the history
  • Loading branch information
markparonyan committed May 14, 2024
1 parent 4898c44 commit 521a046
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions backend/api/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
from sqlalchemy_utils import create_database, drop_database
from sqlalchemy import create_engine

from db.dbapi import DatabaseService


@pytest.fixture
def postgres():
Expand All @@ -19,18 +21,30 @@ def postgres():

@pytest.fixture
def db_connection(postgres):
engine = create_engine(postgres)
engine = create_engine(postgres,
pool_size=10,
max_overflow=2,
pool_recycle=300,
pool_pre_ping=True,
pool_use_lifo=True
)
conn = engine.connect()
db = DatabaseService()
try:
yield conn
yield conn, db
finally:
conn.close()
engine.dispose()


@pytest.fixture
def fill_db(db_connection):
db_connection.execute(
db_connection[0].execute(
"INSERT INTO users (name,hashed_password,lifetime) "
f"VALUES ('existing_user', 'test', '{datetime.now() + timedelta(minutes=30)}')"
f"VALUES ('existing_user', '$2b$12$NlmobQnJ0.EMzOfJ9dZXfuj5lCl4RUuQdkC3MLAKPT/MRV2xJ2Qvi', "
f"'{datetime.now() + timedelta(minutes=30)}')"
)

db_connection[0].execute(f"""INSERT INTO tokens (token,expires_at,"user")
VALUES ('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiZXhpc3RpbmdfdXNlciJ9.9rgns-G5cW9RnadTqfxnmc8he3oGK7ytrsEkXRIAutU',
'{datetime.now() + timedelta(minutes=30)}','existing_user')""")

0 comments on commit 521a046

Please sign in to comment.