-
Notifications
You must be signed in to change notification settings - Fork 1
/
conftest.py
95 lines (72 loc) · 2.38 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
import pytest
from sqlalchemy.orm import sessionmaker
from sqlalchemy_utils import create_database, database_exists, drop_database
from ezrules.backend import ezruleapp, ezrulevalapp
from ezrules.models.backend_core import Organisation, User
from ezrules.models.database import Base, engine
from ezrules.models.history_meta import versioned_session
@pytest.fixture(scope="session")
def logged_out_manager_client():
ezruleapp.app.config["TESTING"] = True
ezruleapp.app.config["WTF_CSRF_METHODS"] = []
with ezruleapp.app.test_client() as client:
yield client
@pytest.fixture(scope="session")
def logged_out_eval_client():
ezrulevalapp.app.config["TESTING"] = True
with ezrulevalapp.app.test_client() as client:
yield client
@pytest.fixture(scope="session")
def engine_fix():
if database_exists(engine.url):
drop_database(engine.url)
create_database(engine.url)
Base.metadata.create_all(
engine
) # Assuming Base is the declarative base from your models
yield engine
Base.metadata.drop_all(engine)
drop_database(engine.url)
@pytest.fixture(scope="session")
def connection(engine_fix):
connection = engine_fix.connect()
yield connection
connection.close()
@pytest.fixture(scope="function")
def session(connection):
transaction = connection.begin()
Session = sessionmaker(bind=connection)
session = Session()
versioned_session(session)
org = Organisation(name="test_org")
session.add(org)
session.commit()
admin_email = f"admin@test_org.com"
admin_password = f"12345678"
session.add(
User(
email=admin_email,
password=admin_password,
active=True,
fs_uniquifier=admin_email,
)
)
session.commit()
ezruleapp.fsrm.db = session
ezruleapp.fsrm.o_id = org.o_id
ezruleapp.rule_engine_config_producer.db = session
ezruleapp.rule_engine_config_producer.o_id = org.o_id
ezrulevalapp.lre.db = session
ezrulevalapp.lre.o_id = org.o_id
yield session
session.close()
transaction.rollback()
@pytest.fixture
def logged_in_manager_client(session, logged_out_manager_client):
# Log in the test user
logged_out_manager_client.post(
"/login",
data=dict(email="admin@test_org.com", password="12345678"),
follow_redirects=True,
)
yield logged_out_manager_client