def load(_, web=False):
    respondent_home_url = os.getenv('RESPONDENT_HOME_URL',
                                    "http://localhost:9092")
    if web:
        run_command(
            f"locust -f tests/load/locustfile.py --host={respondent_home_url}")
    else:
        run_command(f"locust -f tests/load/locustfile.py "
                    f"--no-web -c 1000 -r 50 --run-time 30s "
                    f"--host={respondent_home_url}")
def server(ctx, port=None, reload=True, debug=False, production=True):
    """Run the gunicorn server"""
    try:
        port = port or env('PORT')
    except ConfigurationError:
        print(
            'Port not set. Use `inv server --port=[INT]` or set the PORT environment variable.'
        )
        sys.exit(1)

    log_level = 'DEBUG' if debug else 'INFO'

    if production:
        os.environ['APP_SETTINGS'] = 'ProductionConfig'

    command = (
        'gunicorn "app.app:create_app()" -w 4 '
        f'--bind 0.0.0.0:{port} --worker-class aiohttp.worker.GunicornWebWorker '
        f'--access-logfile - --log-level {log_level}')

    if reload:
        command += ' --reload'
    run_command(command, echo=True)
def cleanpy(ctx):
    """Clear out __pycache__ directories."""
    run_command("find . -path '*/__pycache__/*' -delete", echo=True)
    print('Cleaned up.')
def flake8(ctx):
    """Run flake8 on the codebase"""
    run_command('flake8 app', echo=True)
def coverage(ctx):
    """Calculate coverage and render to HTML"""
    run_command(
        'pytest tests/unit --cov app --cov-report html --ignore=node_modules')
def demo(ctx):
    """Run the demo server"""
    run_command('python -m tests.demo')
def run(ctx, port=None):
    """Run the development server"""
    port = port or env('PORT', default=9092)
    if not os.getenv('APP_SETTINGS'):
        os.environ['APP_SETTINGS'] = 'DevelopmentConfig'
    run_command(f'adev runserver app --port {port}', echo=True)
def demo(_):
    """Run the demo server"""
    run_command("python -m tests.demo")
def flake8(_):
    """Run flake8 on the codebase"""
    run_command("flake8 app", echo=True)