-
Notifications
You must be signed in to change notification settings - Fork 0
/
runservice.py
executable file
·71 lines (60 loc) · 2.3 KB
/
runservice.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
70
71
import os
import click
import random
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)
from flask_migrate import Migrate
from app import create_app, db
from app.models.user import User
from app.models.restaurant import Restaurant
from app.models.menu import Menu
from app.models.product import Product
from app.models.order import Order
from app.models.order_detail import OrderDetail
app = create_app(os.getenv("FLASK_CONFIG") or "default")
migrate = Migrate(app, db)
@app.shell_context_processor
def make_shell_context():
"""Make database operations with shell, without import db"""
return dict(db=db, User=User, Restaurant=Restaurant, Menu=Menu, Product=Product, Order=Order, OrderDetail=OrderDetail)
# with app.app_context():
# #User.insert_user()
# default_user = User(name='customer1'+str(random.randint(0,100)), username='customer1'+str(random.randint(0,100)), email='customer1@customer.com'+str(random.randint(0,100)), password='12345678')
# db.session.add(default_user)
# db.session.commit()
# default_user = User(name='user1'+str(random.randint(0,100)), username='user1'+str(random.randint(0,100)), email='user1@user.com'+str(random.randint(0,100)), password='12345678')
# db.session.add(default_user)
# db.session.commit()
# Restaurant.insert_restaurant()
# Menu.insert_menu()
# Product.insert_product()
@app.cli.command()
def initialvalues():
from app.models.user import User
from app.models.restaurant import Restaurant
from app.models.menu import Menu
from app.models.product import Product
"""Run flask initialvalues : creating initial datas """
User.insert_user()
Restaurant.insert_restaurant()
Menu.insert_menu()
Product.insert_product()
return 1
@app.cli.command()
@click.argument('test_names', nargs=-1)
def test(test_names):
"""Run unit test """
import unittest
if test_names:
"""
flask test tests.test_dataset_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