-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmanage.py
executable file
·55 lines (39 loc) · 1.31 KB
/
manage.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
#! /usr/bin/env python3
import os
import unittest
from flask_migrate import Migrate, MigrateCommand
from flask_script import Manager
from flask import make_response
from src.main.api import create_app, db
# make sure DATABASE_URL is set
db_location = os.getenv("DATABASE_URL", None)
if not db_location:
print("Please set DATABASE_URL to the correct database location.")
exit(1)
app = create_app(os.getenv("STARTER_ENV") or "dev")
app.app_context().push()
manager = Manager(app)
migrate = Migrate(app, db, directory="migrations")
with app.app_context():
if db.engine.url.drivername == 'sqlite':
migrate.init_app(app, db, render_as_batch=True)
else:
migrate.init_app(app, db)
manager.add_command('db', MigrateCommand)
static_folder_root = os.path.join(os.path.dirname(os.path.abspath(__file__)), "build")
app.static_folder = static_folder_root
app.static_url_path = "/static/"
app.url_map.strict_slashes = False
@manager.command
def run(port=5000):
app.run(port=port, debug=True)
@manager.command
def test():
"""Runs the unit tests."""
tests = unittest.TestLoader().discover('src/test/pytest/', pattern='test*.py')
result = unittest.TextTestRunner(verbosity=2).run(tests)
if result.wasSuccessful():
return 0
return 1
if __name__ == '__main__':
manager.run()