FitTrackee/mpwo_api/server.py

51 lines
1.1 KiB
Python
Raw Normal View History

2017-12-16 21:00:46 +01:00
import unittest
from mpwo_api import app, db
from mpwo_api.users.models import User
@app.cli.command()
2018-01-20 19:12:34 +01:00
def drop_db():
2017-12-16 21:00:46 +01:00
db.drop_all()
2018-01-20 19:12:34 +01:00
db.session.commit()
print('Database dropped.')
@app.cli.command()
def init_data():
"""Init the database."""
2018-01-01 16:59:46 +01:00
admin = User(
username='admin',
email='admin@example.com',
password='mpwoadmin')
2017-12-17 09:16:08 +01:00
admin.admin = True
db.session.add(admin)
2017-12-16 21:00:46 +01:00
db.session.commit()
2018-01-20 19:12:34 +01:00
print('Admin created.')
2017-12-16 21:00:46 +01:00
def run_test(test_path='mpwo_api/tests'):
2017-12-16 21:00:46 +01:00
"""Runs the tests without code coverage."""
tests = unittest.TestLoader().discover(
test_path, pattern='test*.py')
2017-12-16 21:00:46 +01:00
result = unittest.TextTestRunner(verbosity=2).run(tests)
if result.wasSuccessful():
return 0
return 1
@app.cli.command()
def test(test_path='mpwo_api/tests'):
"""Runs the tests without code coverage."""
run_test()
@app.cli.command()
def test_local():
"""Runs the tests without code coverage in local machine w/ make."""
run_test('mpwo_api/mpwo_api/tests')
2017-12-16 21:00:46 +01:00
if __name__ == '__main__':
app.run()