2015-01-21 08:32:17 -08:00
|
|
|
# manage.py
|
|
|
|
|
|
|
|
|
|
|
|
import os
|
|
|
|
import unittest
|
|
|
|
import coverage
|
|
|
|
|
2016-07-17 03:47:20 -07:00
|
|
|
from flask_script import Manager
|
|
|
|
from flask_migrate import Migrate, MigrateCommand
|
2015-01-21 08:32:17 -08:00
|
|
|
|
2015-05-07 23:24:20 -07:00
|
|
|
COV = coverage.coverage(
|
2015-11-06 12:16:02 -08:00
|
|
|
branch=True,
|
|
|
|
include='project/*',
|
2015-12-25 05:00:00 -08:00
|
|
|
omit=[
|
|
|
|
'project/tests/*',
|
|
|
|
'project/server/config.py',
|
|
|
|
'project/server/*/__init__.py'
|
|
|
|
]
|
2015-11-06 12:16:02 -08:00
|
|
|
)
|
2015-05-07 23:24:20 -07:00
|
|
|
COV.start()
|
|
|
|
|
2015-12-25 05:00:00 -08:00
|
|
|
from project.server import app, db
|
|
|
|
from project.server.models import User
|
2015-01-21 08:32:17 -08:00
|
|
|
|
|
|
|
|
|
|
|
migrate = Migrate(app, db)
|
|
|
|
manager = Manager(app)
|
|
|
|
|
|
|
|
# migrations
|
|
|
|
manager.add_command('db', MigrateCommand)
|
|
|
|
|
|
|
|
|
|
|
|
@manager.command
|
|
|
|
def test():
|
2016-07-17 09:43:59 -07:00
|
|
|
"""Runs the unit tests without test coverage."""
|
2015-12-25 05:00:00 -08:00
|
|
|
tests = unittest.TestLoader().discover('project/tests', pattern='test*.py')
|
2015-04-16 15:32:22 -07:00
|
|
|
result = unittest.TextTestRunner(verbosity=2).run(tests)
|
|
|
|
if result.wasSuccessful():
|
|
|
|
return 0
|
2016-04-07 17:30:17 -07:00
|
|
|
return 1
|
2015-01-21 08:32:17 -08:00
|
|
|
|
|
|
|
|
|
|
|
@manager.command
|
|
|
|
def cov():
|
|
|
|
"""Runs the unit tests with coverage."""
|
2015-12-25 05:00:00 -08:00
|
|
|
tests = unittest.TestLoader().discover('project/tests')
|
|
|
|
result = unittest.TextTestRunner(verbosity=2).run(tests)
|
|
|
|
if result.wasSuccessful():
|
|
|
|
COV.stop()
|
|
|
|
COV.save()
|
|
|
|
print('Coverage Summary:')
|
|
|
|
COV.report()
|
2017-02-05 12:11:46 -08:00
|
|
|
COV.html_report()
|
2015-12-25 05:00:00 -08:00
|
|
|
COV.erase()
|
|
|
|
return 0
|
2016-04-07 17:30:17 -07:00
|
|
|
return 1
|
2015-01-21 08:32:17 -08:00
|
|
|
|
|
|
|
|
|
|
|
@manager.command
|
|
|
|
def create_db():
|
|
|
|
"""Creates the db tables."""
|
|
|
|
db.create_all()
|
|
|
|
|
|
|
|
|
|
|
|
@manager.command
|
|
|
|
def drop_db():
|
|
|
|
"""Drops the db tables."""
|
|
|
|
db.drop_all()
|
|
|
|
|
|
|
|
|
|
|
|
@manager.command
|
|
|
|
def create_admin():
|
|
|
|
"""Creates the admin user."""
|
|
|
|
db.session.add(User(email='ad@min.com', password='admin', admin=True))
|
|
|
|
db.session.commit()
|
|
|
|
|
|
|
|
|
|
|
|
@manager.command
|
|
|
|
def create_data():
|
|
|
|
"""Creates sample data."""
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
manager.run()
|