forked from indico/newdle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
conftest.py
109 lines (84 loc) · 2.45 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
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
from datetime import datetime, timedelta
import flask_migrate
import pytest
from newdle.core.app import create_app
from newdle.core.db import db
from newdle.models import Newdle, Participant
TEST_DATABASE_URI = 'postgresql:///newdle_tests'
@pytest.fixture(scope='session')
def app():
"""Session-wide test `Flask` application."""
config_override = {
'TESTING': True,
'SQLALCHEMY_DATABASE_URI': TEST_DATABASE_URI,
'SERVER_NAME': 'flask.test',
'SECRET_KEY': 'test',
'EMAIL_BACKEND': 'newdle.vendor.django_mail.backends.locmem.EmailBackend',
}
app = create_app(config_override, use_env_config=False)
ctx = app.app_context()
ctx.push()
yield app
ctx.pop()
@pytest.fixture(scope='session')
def database(app):
flask_migrate.upgrade(revision='head')
yield
flask_migrate.downgrade(revision='base')
@pytest.fixture()
def db_session(app, database):
"""Create a new database session."""
connection = db.engine.connect()
transaction = connection.begin()
options = dict(bind=connection, binds={})
session = db.create_scoped_session(options=options)
db.session = session
db.app = app
yield session
transaction.rollback()
connection.close()
session.remove()
@pytest.fixture
def mail_queue():
from newdle.vendor import django_mail
django_mail.outbox = []
return django_mail.outbox
@pytest.fixture()
def flask_client(app):
return app.test_client()
@pytest.fixture
def dummy_uid():
return 'user123'
@pytest.fixture
def dummy_participant_uid():
return 'pig'
@pytest.fixture
def dummy_newdle(db_session, dummy_uid):
newdle = Newdle(
code='dummy',
title='Test event',
creator_uid=dummy_uid,
creator_name='Dummy',
duration=timedelta(minutes=60),
private=True,
timezone='Europe/Zurich',
timeslots=[
datetime(2019, 9, 11, 13, 0),
datetime(2019, 9, 11, 14, 0),
datetime(2019, 9, 12, 13, 0),
datetime(2019, 9, 12, 13, 30),
],
participants={
Participant(code='part1', name='Tony Stark'),
Participant(code='part2', name='Albert Einstein'),
Participant(
code='part3',
name='Guinea Pig',
email='example@example.com',
auth_uid='pig',
),
},
)
db_session.add(newdle)
db_session.flush()
return newdle