Skip to content

Commit 521a046

Browse files
committed
refactor conftest.py
1 parent 4898c44 commit 521a046

File tree

1 file changed

+18
-4
lines changed

1 file changed

+18
-4
lines changed

backend/api/conftest.py

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
from sqlalchemy_utils import create_database, drop_database
55
from sqlalchemy import create_engine
66

7+
from db.dbapi import DatabaseService
8+
79

810
@pytest.fixture
911
def postgres():
@@ -19,18 +21,30 @@ def postgres():
1921

2022
@pytest.fixture
2123
def db_connection(postgres):
22-
engine = create_engine(postgres)
24+
engine = create_engine(postgres,
25+
pool_size=10,
26+
max_overflow=2,
27+
pool_recycle=300,
28+
pool_pre_ping=True,
29+
pool_use_lifo=True
30+
)
2331
conn = engine.connect()
32+
db = DatabaseService()
2433
try:
25-
yield conn
34+
yield conn, db
2635
finally:
2736
conn.close()
2837
engine.dispose()
2938

3039

3140
@pytest.fixture
3241
def fill_db(db_connection):
33-
db_connection.execute(
42+
db_connection[0].execute(
3443
"INSERT INTO users (name,hashed_password,lifetime) "
35-
f"VALUES ('existing_user', 'test', '{datetime.now() + timedelta(minutes=30)}')"
44+
f"VALUES ('existing_user', '$2b$12$NlmobQnJ0.EMzOfJ9dZXfuj5lCl4RUuQdkC3MLAKPT/MRV2xJ2Qvi', "
45+
f"'{datetime.now() + timedelta(minutes=30)}')"
3646
)
47+
48+
db_connection[0].execute(f"""INSERT INTO tokens (token,expires_at,"user")
49+
VALUES ('eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJuYW1lIjoiZXhpc3RpbmdfdXNlciJ9.9rgns-G5cW9RnadTqfxnmc8he3oGK7ytrsEkXRIAutU',
50+
'{datetime.now() + timedelta(minutes=30)}','existing_user')""")

0 commit comments

Comments
 (0)