-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage.py
88 lines (66 loc) · 2.28 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
# -*- coding: utf-8 -*-
import os
import unittest
import coverage
from flask_script import Manager, Server
from app import create_app, db
from app.init_db import init_data, init_options, init_test_data
from app.utils import config
# import pandas as pd
# from flask_migrate import Migrate, MigrateCommand
COV = coverage.coverage(branch=True, include='app/*')
COV.start()
app = create_app(os.getenv('TYPE', 'default'))
host = config.get_yaml('app.HOST')
port = config.get_yaml('app.PORT')
manager = Manager(app)
manager.add_command('runserver', Server(host=host, port=port))
# migrate = Migrate(app, db)
# manager.add_command('db', MigrateCommand)
@manager.command
def test(filter=None):
"""Run the unit tests"""
loader = unittest.TestLoader()
loader.testNamePatterns = [filter + "*"] if filter is not None else None
tests = loader.discover('tests')
unittest.TextTestRunner(verbosity=2).run(tests)
COV.stop()
COV.save()
print('Coverage:')
COV.report()
basedir = os.path.abspath(os.path.dirname("backend"))
covdir = os.path.join(basedir, 'test_report')
COV.html_report(directory=covdir)
print('HTML version: file://%s/index.html' % covdir)
@manager.command
def init_test_db():
"""Init Database for Testing"""
# recreate the database and the db table
db.drop_all()
db.create_all()
init_options()
init_test_data()
@manager.command
def init_db():
"""Init Database"""
# recreate the database and the db table
db.drop_all()
db.create_all()
init_options()
init_data()
# @manager.command
# def export_metadata():
# writer = pd.ExcelWriter('data\\metadata.xlsx')
# for t in meta.sorted_tables:
# columns = []
# for c in t.columns:
# # print([c.name, c.doc, c.type, c.nullable, c.primary_key, [k.target_fullname for k in c.foreign_keys]])
# columns.append([c.name, c.doc, c.type, c.nullable, c.primary_key])
# df = pd.DataFrame(columns)
# df.columns = ["列名", "描述", "类型", "空值", "主键"]
# df["空值"] = df["空值"].map({False: "No", True: "Yes"})
# df["主键"] = df["主键"].map({False: "No", True: "Yes"})
# df.to_excel(writer, sheet_name=t.name)
# writer.save()
if __name__ == '__main__':
manager.run()