2015-09-15 07:46:35 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# -*- coding: utf-8 -*-
|
2022-10-08 22:01:28 +00:00
|
|
|
"""Management functions for dribdat."""
|
2015-09-15 07:46:35 +00:00
|
|
|
import os
|
2018-10-14 20:44:00 +00:00
|
|
|
import click
|
2017-09-18 21:10:01 +00:00
|
|
|
from flask.cli import FlaskGroup
|
|
|
|
from dribdat.app import init_app
|
2022-10-10 07:57:31 +00:00
|
|
|
from dribdat.utils import strtobool
|
2015-09-15 07:46:35 +00:00
|
|
|
from dribdat.settings import DevConfig, ProdConfig
|
|
|
|
|
|
|
|
HERE = os.path.abspath(os.path.dirname(__file__))
|
|
|
|
TEST_PATH = os.path.join(HERE, 'tests')
|
|
|
|
|
2021-09-29 08:59:55 +00:00
|
|
|
|
2017-09-18 21:10:01 +00:00
|
|
|
def shell_context():
|
2022-10-08 22:01:28 +00:00
|
|
|
"""Return context dict for a shell session."""
|
2017-09-18 21:22:20 +00:00
|
|
|
from dribdat.user.models import User, Event, Project, Category, Activity
|
2021-09-29 08:59:55 +00:00
|
|
|
return {
|
|
|
|
'User': User, 'Event': Event, 'Project': Project,
|
|
|
|
'Category': Category, 'Activity': Activity
|
|
|
|
}
|
|
|
|
|
2015-09-15 07:46:35 +00:00
|
|
|
|
2017-09-18 21:10:01 +00:00
|
|
|
def create_app(script_info=None):
|
2022-10-08 22:01:28 +00:00
|
|
|
"""Initialise the app object."""
|
2017-09-18 21:10:01 +00:00
|
|
|
if os.environ.get("DRIBDAT_ENV") == 'prod':
|
|
|
|
app = init_app(ProdConfig)
|
|
|
|
else:
|
|
|
|
app = init_app(DevConfig)
|
2022-10-10 07:57:31 +00:00
|
|
|
# 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
|
2017-09-18 21:10:01 +00:00
|
|
|
app.shell_context_processor(shell_context)
|
|
|
|
return app
|
|
|
|
|
2021-09-29 08:59:55 +00:00
|
|
|
|
2023-07-18 11:26:28 +00:00
|
|
|
def testrunner(name, warnings=None):
|
|
|
|
"""Runs the name with warnings"""
|
2022-10-08 22:01:28 +00:00
|
|
|
if len(name):
|
2022-02-11 13:17:51 +00:00
|
|
|
feat_test = os.path.join(TEST_PATH, "test_%s.py" % name)
|
|
|
|
else:
|
|
|
|
feat_test = TEST_PATH
|
|
|
|
import subprocess
|
2023-07-18 11:26:28 +00:00
|
|
|
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")
|
2015-09-15 07:46:35 +00:00
|
|
|
|
2021-03-15 22:06:16 +00:00
|
|
|
|
|
|
|
@click.group(cls=FlaskGroup, create_app=create_app)
|
|
|
|
def cli():
|
2022-10-08 22:01:28 +00:00
|
|
|
"""Script for managing this application."""
|
|
|
|
pass
|
2021-03-15 22:06:16 +00:00
|
|
|
|
2021-09-29 08:59:55 +00:00
|
|
|
|
2021-03-15 22:06:16 +00:00
|
|
|
cli.add_command(test)
|
|
|
|
|
2015-09-15 07:46:35 +00:00
|
|
|
if __name__ == '__main__':
|
2017-09-18 21:10:01 +00:00
|
|
|
cli()
|