-
Notifications
You must be signed in to change notification settings - Fork 33
/
giya.py
50 lines (34 loc) · 1.13 KB
/
giya.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
import os
from dotenv import load_dotenv
dotenv_path = os.path.join(os.path.dirname(__file__), ".env")
if os.path.exists(dotenv_path):
load_dotenv(dotenv_path)
##
import click
from flask_migrate import Migrate
from app import create_app, db
# Import models
from app.models.user import User, Role, Permission
app = create_app(os.getenv("FLASK_CONFIG") or "default")
migrate = Migrate(app, db)
@app.shell_context_processor
def make_shell_context():
return dict(db=db, User=User, Role=Role, Permission=Permission)
@app.cli.command()
@click.argument("test_names", nargs=-1)
def test(test_names):
""" Run unit tests """
import unittest
if test_names:
""" Run specific unit tests.
Example:
$ flask test tests.test_auth_api tests.test_user_model ...
"""
tests = unittest.TestLoader().loadTestsFromNames(test_names)
else:
tests = unittest.TestLoader().discover("tests", pattern="test*.py")
result = unittest.TextTestRunner(verbosity=2).run(tests)
if result.wasSuccessful():
return 0
# Return 1 if tests failed, won't reach here if succeeded.
return 1