-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathconftest.py
81 lines (64 loc) · 1.95 KB
/
conftest.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import calendar
import pytest
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from app.config import PSQL_ENVIRONMENT
from app.database.models import Base
pytest_plugins = [
'tests.user_fixture',
'tests.event_fixture',
'tests.dayview_fixture',
'tests.invitation_fixture',
'tests.association_fixture',
'tests.client_fixture',
'tests.asyncio_fixture',
'tests.logger_fixture',
'tests.category_fixture',
'smtpdfix',
'tests.quotes_fixture',
'tests.zodiac_fixture',
'tests.comment_fixture',
]
# When testing in a PostgreSQL environment please make sure that:
# - Base string is a PSQL string
# - app.config.PSQL_ENVIRONMENT is set to True
if PSQL_ENVIRONMENT:
SQLALCHEMY_TEST_DATABASE_URL = (
"postgresql://postgres:1234"
"@localhost/postgres"
)
test_engine = create_engine(
SQLALCHEMY_TEST_DATABASE_URL
)
else:
SQLALCHEMY_TEST_DATABASE_URL = "sqlite:///./test.db"
test_engine = create_engine(
SQLALCHEMY_TEST_DATABASE_URL, connect_args={"check_same_thread": False}
)
TestingSessionLocal = sessionmaker(
autocommit=False, autoflush=False, bind=test_engine)
def get_test_db():
return TestingSessionLocal()
@pytest.fixture
def session():
Base.metadata.create_all(bind=test_engine)
session = get_test_db()
yield session
session.rollback()
session.close()
Base.metadata.drop_all(bind=test_engine)
@pytest.fixture
def sqlite_engine():
SQLALCHEMY_TEST_DATABASE_URL = "sqlite:///./test.db"
sqlite_test_engine = create_engine(
SQLALCHEMY_TEST_DATABASE_URL, connect_args={"check_same_thread": False}
)
TestingSession = sessionmaker(
autocommit=False, autoflush=False, bind=sqlite_test_engine)
yield sqlite_test_engine
session = TestingSession()
session.close()
Base.metadata.drop_all(bind=sqlite_test_engine)
@pytest.fixture
def Calendar():
return calendar.Calendar(0)