dribdat/manage.py

63 lines
1.4 KiB
Python
Raw Normal View History

2015-09-15 07:46:35 +00:00
#!/usr/bin/env python
# -*- coding: utf-8 -*-
2017-09-18 21:10:01 +00:00
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
2015-09-15 07:46:35 +00:00
2017-09-18 21:10:01 +00:00
from dribdat.app import init_app
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')
2017-09-18 21:10:01 +00:00
def shell_context():
"""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
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):
"""Initialise the app object"""
if os.environ.get("DRIBDAT_ENV") == 'prod':
app = init_app(ProdConfig)
else:
app = init_app(DevConfig)
app.shell_context_processor(shell_context)
return app
@click.command()
2021-11-18 15:04:25 +00:00
@click.option('--name', default="features", help='Which test file to run.')
def featuretest(name):
2021-03-15 22:06:16 +00:00
"""Run feature tests."""
import pytest
2021-11-18 15:04:25 +00:00
feat_test = os.path.join(TEST_PATH, "test_%s.py" % name)
2021-03-15 22:06:16 +00:00
return pytest.main([feat_test, '--disable-warnings'])
2015-09-15 07:46:35 +00:00
@click.command()
2015-09-15 07:46:35 +00:00
def test():
2021-03-15 22:06:16 +00:00
"""Run all tests."""
2015-09-15 07:46:35 +00:00
import pytest
test_opts = [TEST_PATH]
exit_code = pytest.main(test_opts)
2015-09-15 07:46:35 +00:00
return exit_code
2021-03-15 22:06:16 +00:00
@click.group(cls=FlaskGroup, create_app=create_app)
def cli():
"""This is a management script for this application."""
2021-03-15 22:06:16 +00:00
cli.add_command(test)
cli.add_command(featuretest)
2015-09-15 07:46:35 +00:00
if __name__ == '__main__':
2017-09-18 21:10:01 +00:00
cli()