-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanage.py
More file actions
89 lines (65 loc) · 1.85 KB
/
manage.py
File metadata and controls
89 lines (65 loc) · 1.85 KB
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
import unittest
import coverage
import os
from src.app import app
from src import db
from src.model.user import User
from flask_script import Manager
manager = Manager(app)
@manager.option('-m', '--module', dest='module')
def test(module):
if module:
tests = unittest.TestLoader().loadTestsFromName(module)
else:
tests = unittest.TestLoader().discover('tests')
result = unittest.TextTestRunner(verbosity=2).run(tests)
if result.wasSuccessful():
return 0
return 1
@manager.option('-m', '--module', dest='module')
def cov(module):
"""Runs the unit tests with coverage."""
cov = coverage.Coverage(
branch=True,
cover_pylib=False,
data_file='.coverage',
include=[
'tests/*',
'app/api/*'
],
omit='.venv/*'
)
cov.start()
if module:
tests = unittest.TestLoader().loadTestsFromName(module)
else:
tests = unittest.TestLoader().discover('tests')
result = unittest.TextTestRunner(verbosity=2).run(tests)
if result.wasSuccessful():
cov.stop()
cov.save()
print('\n\nCoverage Summary:\n')
cov.report()
basedir = os.path.abspath(os.path.dirname(__file__))
covdir = os.path.join(basedir, '.tmp/coverage')
cov.html_report(directory=covdir)
print('\n\nHTML version: file://%s/index.html\n' % covdir)
cov.erase()
return 0
return 1
@manager.command
def create_db_tables():
if db.create_all():
return 0
return 1
@manager.option('-p', '--password', dest='password')
def create_admin(password):
if not password:
password = 'password'
admin = User('admin', password, True, 'ADMIN')
db.session.add(admin)
if db.session.commit():
return 0
return 1
if __name__ == '__main__':
manager.run()