-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathseed_db.py
60 lines (49 loc) · 2.18 KB
/
seed_db.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
import json
from application_store._helpers import get_blank_forms
from application_store.db.models.application import Applications
from application_store.db.queries import add_new_forms
from application_store.db.queries.application import (
create_application,
submit_application,
)
from application_store.db.queries.updating.queries import update_form
def seed_not_started_application(fund_config, round_config, account_id, language):
return _seed_application(fund_config["id"], round_config["id"], account_id, language)
def seed_in_progress_application(fund_config, round_config, account_id, language):
app = _seed_application(fund_config["id"], round_config["id"], account_id, language)
with open(
f"tests/application_store_tests/seed_data/{fund_config['short_code']}_{round_config['short_code']}_all_forms.json",
) as f:
ALL_FORMS = json.load(f)
form = [form for form in ALL_FORMS if form["name"] == round_config["project_name_form"]][0]
update_form(
app.id,
round_config["project_name_form"],
form["questions"],
True,
)
return app
def seed_completed_application(fund_config, round_config, account_id, language):
app = _seed_application(fund_config["id"], round_config["id"], account_id, language)
with open(
f"tests/application_store_tests/seed_data/{fund_config['short_code']}_{round_config['short_code']}_all_forms.json",
) as f:
ALL_FORMS = json.load(f)
for form in ALL_FORMS:
update_form(
app.id,
form["name"],
form["questions"],
True,
)
return app
def seed_submitted_application(fund_config, round_config, account_id, language):
app = seed_completed_application(fund_config, round_config, account_id, language)
submit_application(str(app.id))
return app
def _seed_application(fund_id, round_id, account_id, language) -> Applications:
app: Applications = create_application(account_id, fund_id, round_id, language)
empty_forms = get_blank_forms(fund_id, round_id, language)
add_new_forms(forms=empty_forms, application_id=app.id)
print(f"Created app with reference {app.reference}")
return app