-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage.py
110 lines (92 loc) · 2.86 KB
/
manage.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
110
# manage.py
import unittest
import coverage
import urllib.parse
from flask.cli import FlaskGroup
from project import app
from project.extensions import db
from project.models.user import User
from project.models.event_descriptor import EventDescriptor
from project.models.group import Group
from project.models.user_group_association import UserGroupAssociation
cli = FlaskGroup(app)
COV = coverage.coverage(
branch=True,
include='project/*',
omit=[
'project/static/*'
]
)
COV.start()
@cli.command()
def test():
"""Runs the tests without code coverage."""
tests = unittest.TestLoader().discover('tests', pattern='test_*.py')
result = unittest.TextTestRunner(verbosity=2).run(tests)
if result.wasSuccessful():
return 0
return 1
@cli.command('recreate_db')
def recreate_db():
"""Recreates a database."""
db.reflect()
db.drop_all()
db.create_all()
db.session.commit()
@cli.command('recreate_test_db')
def recreate_test_db():
"""Recreates testing database."""
app.config.from_object('project.config.TestingConfig')
db.reflect()
db.drop_all()
db.create_all()
db.session.commit()
@cli.command('drop_test_db')
def drop_db():
"""Drop testing database."""
app.config.from_object('project.config.TestingConfig')
db.reflect()
db.drop_all()
db.session.commit()
@cli.command('drop_db')
def drop_db():
"""Drop a database."""
db.reflect()
db.drop_all()
db.session.commit()
@cli.command('seed_db')
def seed_db():
"""Seeds the database."""
event_desc = EventDescriptor(id=1, name="Seed Events Name", description="Seed db Event from {1}")
db.session.add(event_desc)
group = Group(name="Group Name")
db.session.add(group)
user1 = User(username='martin', email="[email protected]", password="password", cellphone_number="98983510", cellphone_cc="+598")
user2 = User(username='barreto', email="[email protected]", password="password")
user3 = User(username='cheluskis', email="[email protected]", password="password")
db.session.add(user1)
db.session.add(user2)
db.session.add(user3)
user_group_association1 = UserGroupAssociation(user=user1, group=group)
db.session.add(user_group_association1)
user_group_association2 = UserGroupAssociation(user=user2, group=group)
db.session.add(user_group_association2)
user_group_association3 = UserGroupAssociation(user=user3, group=group)
db.session.add(user_group_association3)
db.session.commit()
@cli.command()
def cov():
"""Runs the unit tests with coverage."""
tests = unittest.TestLoader().discover('tests')
result = unittest.TextTestRunner(verbosity=2).run(tests)
if result.wasSuccessful():
COV.stop()
COV.save()
print('Coverage Summary:')
COV.report()
COV.html_report()
COV.erase()
return 0
return 1
if __name__ == '__main__':
cli()