-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtasks.py
72 lines (55 loc) · 1.92 KB
/
tasks.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
from invoke import task
@task
def test(c, cov=False, cov_report=False, junit=False, enforce_percent=0):
""" Run unit tests. """
command = "pytest"
if cov_report:
command += " --cov-report=html"
if junit:
command += " --junitxml=test-results/results.xml"
if enforce_percent > 0:
command += f" --cov-fail-under={enforce_percent}"
if cov or cov_report or junit or enforce_percent:
command += " --cov app"
else:
command += " app tests"
c.run(command)
@task
def style(c, fix=False):
""" Run black checks against the codebase. """
command = "black"
if not fix:
command += " --check"
c.run(f"{command} app tests")
@task
def lint(c, fail_under=0):
""" Run pylint checks against the codebase """
command = "pylint --rcfile=.pylintrc"
if fail_under > 0:
command += f" --fail-under={fail_under}"
c.run(f"{command} app")
@task
def precommit(c, fix=False):
test(c, junit=True, enforce_percent=92)
style(c, fix=fix)
lint(c, fail_under=9)
@task
def create_user(c, email, password, first_name, last_name, is_system_admin=False):
""" Create a user. Returns the UUID of the organization. """
from app import create_app, models, services
(app, db, _) = create_app()
with app.app_context():
user = services.create_user(email, password, first_name, last_name)
user.is_system_admin = is_system_admin
models.db.session.commit()
print(user.uuid)
@task
def create_organization(c, name, email):
""" Create an organization for a user with 'email'. Returns the UUID of the organization. """
from app import create_app, models, services, queries
(app, db, _) = create_app()
with app.app_context():
user = queries.find_user_by_email(email)
organization = services.create_organization(name, user)
models.db.session.commit()
print(organization.uuid)