-
Notifications
You must be signed in to change notification settings - Fork 0
/
db_scripts.py
67 lines (59 loc) · 1.61 KB
/
db_scripts.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
from app import db, app
from app.models import Attack, Defence, Match, Team, User
def flush_matches():
for a in Attack.query.all():
db.session.delete(a)
db.session.commit()
for m in Match.query.all():
db.session.delete(m)
db.session.commit()
app.config["ROUND"] = 1
def flush_whole_db():
flush_matches()
for d in Defence.query.all():
db.session.delete(d)
db.session.commit()
for t in Team.query.all():
db.session.delete(t)
db.session.commit()
for u in User.query.all():
db.session.delete(u)
db.session.commit()
def populate_test_users():
flush_whole_db()
for i, u_name in enumerate(
[
"alice",
"bob",
"charlie",
"dimitri",
"eugene",
"francois",
"gerald",
"hector",
"ignatus",
"john",
]
):
u = User(
username=u_name,
email=app.config["MAIL_TEST_RECEIVER_FORMAT"].format(u_name),
sciper=1001 + i,
)
db.session.add(u)
db.session.commit()
u.set_password("admin")
admin = User(
username="admin",
email=app.config["MAIL_TEST_RECEIVER_FORMAT"].format("admin"),
sciper=1000,
is_admin=True,
)
db.session.add(admin)
db.session.commit()
admin.set_password("admin")
for i, t_name in enumerate(["al-bo", "cha-di", "eu-fra", "ger-hec", "ign-joh"]):
db.session.add(
Team(team_name=t_name, member1_id=2 * i + 1, member2_id=2 * i + 2)
)
db.session.commit()