forked from dribdat/dribdat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
manage.py
executable file
·83 lines (67 loc) · 2.35 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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""Management functions for dribdat."""
import os
import click
from flask.cli import FlaskGroup
from dribdat.app import init_app
from dribdat.utils import strtobool
from dribdat.settings import DevConfig, ProdConfig
HERE = os.path.abspath(os.path.dirname(__file__))
TEST_PATH = os.path.join(HERE, 'tests')
def shell_context():
"""Return context dict for a shell session."""
from dribdat.user.models import User, Event, Project, Category, Activity
return {
'User': User, 'Event': Event, 'Project': Project,
'Category': Category, 'Activity': Activity
}
def create_app(script_info=None):
"""Initialise the app object."""
if os.environ.get("DRIBDAT_ENV") == 'prod':
app = init_app(ProdConfig)
else:
app = init_app(DevConfig)
# Enable debugger and profiler
if bool(strtobool(os.environ.get("FLASK_DEBUG", "False"))):
app.config['DEBUG_TB_PROFILER_ENABLED'] = True
app.debug = True
#from flask_debugtoolbar import DebugToolbarExtension
#DebugToolbarExtension(app)
# from werkzeug.middleware.profiler import ProfilerMiddleware
# app.wsgi_app = ProfilerMiddleware(
# app.wsgi_app,
# restrictions=[5, 'public'],
# profile_dir='./profile',
# )
# Pass through shell commands
app.shell_context_processor(shell_context)
return app
def testrunner(name, warnings=None):
"""Runs the name with warnings"""
if len(name):
feat_test = os.path.join(TEST_PATH, "test_%s.py" % name)
else:
feat_test = TEST_PATH
import subprocess
if warnings is None:
return subprocess.call(['pytest', feat_test])
return subprocess.call(['pytest', warnings, feat_test])
@click.command()
@click.argument('name', nargs=-1, required=False)
def test(name):
"""Run all or just a subset of tests."""
"""Parameter: which test set to run (features, functional, ..)"""
return testrunner(name)
@click.command()
@click.argument('name', nargs=-1, required=False)
def testwarn(name):
"""Run all or just a subset of tests with warnings."""
return testrunner(name, "-W default")
@click.group(cls=FlaskGroup, create_app=create_app)
def cli():
"""Script for managing this application."""
pass
cli.add_command(test)
if __name__ == '__main__':
cli()