-
Notifications
You must be signed in to change notification settings - Fork 52
Expand file tree
/
Copy pathconftest.py
More file actions
152 lines (122 loc) · 3.83 KB
/
conftest.py
File metadata and controls
152 lines (122 loc) · 3.83 KB
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import calendar
from datetime import datetime
import pytest
from sqlalchemy import create_engine
from sqlalchemy.orm import sessionmaker
from app.config import PSQL_ENVIRONMENT
from app.database.models import Base
from app.routers.event import create_event
from app.routers.user import create_user
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.jokes_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)
@pytest.fixture
def no_event_user(session):
"""a user made for testing who doesn't own any event."""
user = create_user(
session=session,
username='new_test_username',
password='new_test_password',
email='new2_test.email@gmail.com',
language_id='english'
)
return user
@pytest.fixture
def event_owning_user(session):
"""a user made for testing who already owns an event."""
user = create_user(
session=session,
username='new_test_username2',
password='new_test_password2',
email='new_test_love231.email@gmail.com',
language_id='english'
)
data = {
'title': 'event_owning_user event',
'start': datetime.strptime('2021-05-05 14:59', '%Y-%m-%d %H:%M'),
'end': datetime.strptime('2021-05-05 15:01', '%Y-%m-%d %H:%M'),
'location': 'https://us02web.zoom.us/j/875384596',
'content': 'content',
'owner_id': user.id,
}
create_event(session, **data)
return user
@pytest.fixture
def user1(session):
"""another user made for testing"""
user = create_user(
session=session,
username='user2user2',
password='verynicepass',
email='trulyyours1.email@gmail.com',
language_id='english'
)
return user
@pytest.fixture
def event_example(session, event_owning_user):
data = {
'title': 'test event title',
'start': datetime.strptime('2021-05-05 14:59', '%Y-%m-%d %H:%M'),
'end': datetime.strptime('2021-05-05 15:01', '%Y-%m-%d %H:%M'),
'location': 'https://us02web.zoom.us/j/87538459r6',
'content': 'content',
'owner_id': event_owning_user.id,
}
event = create_event(session, **data)
return event