Ejemplo n.º 1
0
 def test_adds(self):
     session.add_all([
         Menu(title='orderManage'),
         Menu(title='vipManage', url='/user1', parent_id=1),
         Menu(title='friend', url='/user2', parent_id=1)
     ])
     session.commit()
Ejemplo n.º 2
0
 def test_adds(self):
     session.add_all([
         Menu(title='订单管理'),
         Menu(title='会员管理', url='/user', parent_id=1),
         Menu(title='派件员', url='/user2', parent_id=1),
         Menu(title='合作商', url='/user3', parent_id=1),
         Menu(title='订单统计', url='/order_cnt', parent_id=2),
     ])
     session.commit()
Ejemplo n.º 3
0
 def test_add(self):
     # m1 = Menu(title='用户管理')
     # session.add(m1)
     session.add_all([
         Menu(title='订单管理'),
         Menu(title='会员管理', url='/user1', parent_id=1),
         Menu(title='派件员', url='/user2', parent_id=1),
         Menu(title='合作商', url='/user3', parent_id=1),
         Menu(title='订单统计', url='/order_cnt', parent_id=2)
     ])
     session.commit()
Ejemplo n.º 4
0
 def test_add(self):
     m1 = Menu()
     m1.title = '艹'
     m1.name = ''
     session.add(m1)
     if session.commit():
         print('success')
Ejemplo n.º 5
0
def menu_store():
    form = MenuCreateForm(request.form)
    if form.validate():
        menu = Menu()
        menu.create(data=form.data)
        return Success(message="操作成功!")
    return Fail(message=form.first_error)
 def setUp(self):
     self.BaseSetUp()
     self.mock_vendor = Vendor(id=1,
                               created_at=datetime.now(),
                               updated_at=datetime.now(),
                               name='Mock vendor',
                               address='Mock address',
                               tel='',
                               contact_person='Mock person',
                               is_active=True,
                               location_id=1)
     self.mock_vendor_engagement = VendorEngagement(
         id=1,
         created_at=datetime.now(),
         updated_at=datetime.now(),
         vendor_id=1,
         location_id=1,
         start_date=datetime.now(),
         end_date=datetime.now(),
         status=1,
         termination_reason='Mock reason',
         vendor=self.mock_vendor)
     self.mock_menu = Menu(is_deleted=False,
                           date=datetime.now(),
                           meal_period='',
                           location_id=1,
                           main_meal_id=1,
                           allowed_side=1,
                           allowed_protein=1,
                           side_items='',
                           protein_items='',
                           vendor_engagement_id=1,
                           created_at=datetime.now(),
                           updated_at=datetime.now())
     self.mock_vendor_engagement = VendorEngagement(
         id=1,
         created_at=datetime.now(),
         updated_at=datetime.now(),
         vendor_id=1,
         location_id=1,
         start_date=datetime.now(),
         end_date=datetime.now(),
         status=1,
         termination_reason='Mock reason',
         vendor=self.mock_vendor,
         menus=[
             self.mock_menu,
         ])
     self.mock_vendor_engagement_no_child = VendorEngagement(
         id=1,
         created_at=datetime.now(),
         updated_at=datetime.now(),
         vendor_id=1,
         location_id=1,
         start_date=datetime.now(),
         end_date=datetime.now(),
         status=1,
         termination_reason='Mock reason',
         vendor=self.mock_vendor)
Ejemplo n.º 7
0
def add_menu():
    form = MenuForm().validate_for_api()
    with db.auto_commit():
        menu = Menu()
        menu.menu_name = form.menu_name.data
        menu.en_name = form.en_name.data
        menu.create_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime())
        db.session.add(menu)
    return restful_json(menu)
Ejemplo n.º 8
0
def create_menu(name, endpoint):
    """
    设置角色
    :param name:
    :param label:
    :return:
    """
    with db.auto_commit():
        menu = Menu()
        menu.name = name
        menu.endpoint = endpoint
        menu.pid = 0
        menu.active = 1
        menu.target = 1
        db.session.add(menu)
    print("成功创建后台导航: %s " % (name, ))
Ejemplo n.º 9
0
 def new_menu(self, date, meal_period, main_meal_id, allowed_side,
              allowed_protein, side_items, protein_items,
              vendor_engagement_id, location_id):
     date = datetime.strptime(date, '%Y-%m-%d')
     meal_period = meal_period.lower()
     menu = Menu(date=date,
                 meal_period=meal_period,
                 main_meal_id=main_meal_id,
                 allowed_side=allowed_side,
                 allowed_protein=allowed_protein,
                 side_items=','.join(str(item) for item in side_items),
                 protein_items=','.join(
                     str(item) for item in protein_items),
                 vendor_engagement_id=vendor_engagement_id,
                 location_id=location_id)
     menu.save()
     return menu
Ejemplo n.º 10
0
    def test_handle_placing_order(self, func_get_unpaginated):
        # LocationFactory.create(name='Lagos')
        with self.app.app_context():
            m_menu = Menu(id=1, main_meal=MealItem(name='Main meal 1'))
            func_get_unpaginated.return_value = [
                m_menu,
            ]
            m_date = date.today().strftime('%Y-%m-%d')
            m_location_id = LocationRepo().get_unpaginated(name='Lagos')[0].id
            m_meal_period = MealSessionRepo().new_meal_session(
                name='lunch',
                start_time=time(hour=12, minute=20, second=0),
                stop_time=time(hour=14, minute=0, second=0),
                location_id=m_location_id,
                date=m_date).name

            m_value = f'{m_meal_period}_{m_date}_menu_{m_location_id}'
            m_payload = {'actions': [{'value': m_value}]}
            bot_controller = BotController(self.request_context)

            # Act
            result = bot_controller.handle_placing_order(m_payload)

            # Assert
            if result.status_code != 200:
                raise AssertionError()
            result_json = result.get_json()
            if 'text' not in result_json:
                raise AssertionError()
            if result_json['text'] != 'Select Main Meal':
                raise AssertionError()
            if 'attachments' not in result_json:
                raise AssertionError()
            if result_json['attachments'] is None:
                raise AssertionError()
            if 'text' not in result_json['attachments'][0]:
                raise AssertionError()
            if result_json['attachments'][0]['text'] != '':
                raise AssertionError()
            if 'callback_id' not in result_json['attachments'][0]:
                raise AssertionError()
            if result_json['attachments'][0]['callback_id'] != \
                    'meal_action_selector':
                raise AssertionError()
            if 'color' not in result_json['attachments'][0]:
                raise AssertionError()
            if result_json['attachments'][0]['color'] != '#3AA3E3':
                raise AssertionError()
            if 'attachment_type' not in result_json['attachments'][0]:
                raise AssertionError()
            if result_json['attachments'][0]['attachment_type'] != 'default':
                raise AssertionError()
            if 'actions' not in result_json['attachments'][0]:
                raise AssertionError()
            if result_json['attachments'][0]['actions'] is None:
                raise AssertionError()
            if 'name' not in result_json['attachments'][0]['actions'][0]:
                raise AssertionError()
            if result_json['attachments'][0]['actions'][0]['name'] != \
                    'main_meal':
                raise AssertionError()
            if 'type' not in result_json['attachments'][0]['actions'][0]:
                raise AssertionError()
            if result_json['attachments'][0]['actions'][0]['type'] != 'button':
                raise AssertionError()
            if 'text' not in result_json['attachments'][0]['actions'][0]:
                raise AssertionError()
            if result_json['attachments'][0]['actions'][0]['text'] != \
                    'Main meal 1':
                raise AssertionError()
            if 'value' not in result_json['attachments'][0]['actions'][0]:
                raise AssertionError()
            if result_json['attachments'][0]['actions'][0]['value'] != \
                    f'1_{m_value}':
                raise AssertionError()
Ejemplo n.º 11
0
    def test_handle_action_selection(self, func_get_unpaginated, func_get,
                                     func_get_meal_items_by_ids):
        with self.app.app_context():
            # Arrange
            m_menu = Menu(side_items='item 1', protein_items='item 1')
            func_get_unpaginated.return_value = [
                m_menu,
            ]
            func_get.return_value.name = 'Main meal 1'
            func_get_meal_items_by_ids.return_value = [
                'item 1',
            ]
            m_date = date.today().strftime('%Y-%m-%d')
            m_location_id = LocationRepo().get_unpaginated(name='Lagos')[0].id
            m_meal_session = MealSessionRepo().new_meal_session(
                name='lunch',
                start_time=time(hour=12, minute=20, second=0),
                stop_time=time(hour=14, minute=0, second=0),
                location_id=m_location_id,
                date=m_date)

            m_value = f'{m_meal_session.name}_{m_date}_menu_{m_location_id}'
            m_payload = {'actions': [{'value': m_value}]}
            bot_controller = BotController(self.request_context)

            # Act
            result = bot_controller.handle_action_selection(m_payload)

            # Assert
            if result.status_code != 200:
                raise AssertionError()
            result_json = result.get_json()
            if 'text' not in result_json:
                raise AssertionError()
            if result_json['text'] != m_meal_session.name.upper():
                raise AssertionError()
            if 'attachments' not in result_json:
                raise AssertionError()
            if result_json['attachments'] is None:
                raise AssertionError()
            if 'text' not in result_json['attachments'][0]:
                raise AssertionError()
            expected_text = 'Main meal: *Main meal 1*\n ' \
                            'Side items: item 1\n' \
                            'Protein items: item 1\n\n\n'
            if result_json['attachments'][0]['text'] != expected_text:
                raise AssertionError()
            if 'callback_id' not in result_json['attachments'][0]:
                raise AssertionError()
            if result_json['attachments'][0]['callback_id'] != \
                    'after_menu_list':
                raise AssertionError()
            if 'color' not in result_json['attachments'][0]:
                raise AssertionError()
            if result_json['attachments'][0]['color'] != '#3AA3E3':
                raise AssertionError()
            if 'attachment_type' not in result_json['attachments'][0]:
                raise AssertionError()
            if result_json['attachments'][0]['attachment_type'] != 'default':
                raise AssertionError()
            if 'actions' not in result_json['attachments'][0]:
                raise AssertionError()
            if result_json['attachments'][0]['actions'] is None:
                raise AssertionError()
            if 'name' not in result_json['attachments'][0]['actions'][0]:
                raise AssertionError()
            if result_json['attachments'][0]['actions'][0]['name'] != \
                    'main meal':
                raise AssertionError()
            if 'text' not in result_json['attachments'][0]['actions'][0]:
                raise AssertionError()
            if result_json['attachments'][0]['actions'][0]['text'] != \
                    'Rate meal':
                raise AssertionError()
            if 'type' not in result_json['attachments'][0]['actions'][0]:
                raise AssertionError()
            if result_json['attachments'][0]['actions'][0]['type'] != \
                    'button':
                raise AssertionError()
            if 'value' not in result_json['attachments'][0]['actions'][0]:
                raise AssertionError()
            if result_json['attachments'][0]['actions'][0]['value'] != \
                    f'{m_meal_session.name}_{m_date}_rate_{m_location_id}_{m_location_id}':
                raise AssertionError()
            if 'name' not in result_json['attachments'][0]['actions'][1]:
                raise AssertionError()
            if result_json['attachments'][0]['actions'][0]['name'] != \
                    'main meal':
                raise AssertionError()
            if 'text' not in result_json['attachments'][0]['actions'][1]:
                raise AssertionError()
            if result_json['attachments'][0]['actions'][1]['text'] != \
                    'Place an order':
                raise AssertionError()
            if 'type' not in result_json['attachments'][0]['actions'][1]:
                raise AssertionError()
            if result_json['attachments'][0]['actions'][1]['type'] != \
                    'button':
                raise AssertionError()
            if 'value' not in result_json['attachments'][0]['actions'][1]:
                raise AssertionError()
            if result_json['attachments'][0]['actions'][1]['value'] != \
                    f'{m_meal_session.name}_{m_date}_order_{m_location_id}_{m_location_id}':
                raise AssertionError()
Ejemplo n.º 12
0
    def test_add(self):
        m1 = Menu()
        m1.title = '用户管理'

        session.add(m1)
        session.commit()
Ejemplo n.º 13
0
from app.models.database import DatabaseConnection
# from flask_jwt import JWT, jwt_required
# from app.authentication import authenticate, identity
#app = Flask(__name__)
from app.models.order import Orders
from app.models.menu import Menu
from app.user import User

api = Api(app)
app.secret_key = 'dave'
# jwt = JWT(app, authenticate)
# orders = []

database = DatabaseConnection()
order = Orders()
menu = Menu()
user = User()

database.create_user_table()
database.create_menu_list()
cur = database.cursor
"""
    Handling the order endpoints
"""


#getting all the orders from the database
@app.route('/orders', methods=['GET'])
def get_all_orders():
    response = order.get()
    return jsonify({'orders': response})