-
Notifications
You must be signed in to change notification settings - Fork 199
/
wsgi.py
69 lines (52 loc) · 1.92 KB
/
wsgi.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
import click, pytest, sys
from flask import Flask
from flask.cli import with_appcontext, AppGroup
from App.database import db, get_migrate
from App.models import User
from App.main import create_app
from App.controllers import ( create_user, get_all_users_json, get_all_users, initialize )
# This commands file allow you to create convenient CLI commands for testing controllers
app = create_app()
migrate = get_migrate(app)
# This command creates and initializes the database
@app.cli.command("init", help="Creates and initializes the database")
def init():
initialize()
print('database intialized')
'''
User Commands
'''
# Commands can be organized using groups
# create a group, it would be the first argument of the comand
# eg : flask user <command>
user_cli = AppGroup('user', help='User object commands')
# Then define the command and any parameters and annotate it with the group (@)
@user_cli.command("create", help="Creates a user")
@click.argument("username", default="rob")
@click.argument("password", default="robpass")
def create_user_command(username, password):
create_user(username, password)
print(f'{username} created!')
# this command will be : flask user create bob bobpass
@user_cli.command("list", help="Lists users in the database")
@click.argument("format", default="string")
def list_user_command(format):
if format == 'string':
print(get_all_users())
else:
print(get_all_users_json())
app.cli.add_command(user_cli) # add the group to the cli
'''
Test Commands
'''
test = AppGroup('test', help='Testing commands')
@test.command("user", help="Run User tests")
@click.argument("type", default="all")
def user_tests_command(type):
if type == "unit":
sys.exit(pytest.main(["-k", "UserUnitTests"]))
elif type == "int":
sys.exit(pytest.main(["-k", "UserIntegrationTests"]))
else:
sys.exit(pytest.main(["-k", "App"]))
app.cli.add_command(test)