示例#1
0
def edit_meal(active_user, mealId):
    '''Edit meal'''
    if not active_user['admin']:
        return 'Only available for Admin!'

    if request.json:
        new_meal = Caterer().modify_meal(mealId,
                                     request.json['meal_name'], request.json['price'], request.json['category'], request.json['day'])
        return jsonify({"message": new_meal})

    new_meal = Caterer().modify_meal(mealId, request.form.get('meal_name'), 
                                     request.form.get('price'), request.form.get('category'), request.form.get('day'))
    return jsonify({"message": new_meal})
示例#2
0
def setup_menu(active_user):
    '''Menu set up'''
    if not active_user['admin']:
        return 'Only available for Admin!'

    if request.json:
        post_menu = Caterer().post_menu(request.json['meal_id'], request.json['meal_name'],
                                    request.json['price'], request.json['category'], request.json['day'])
        return jsonify({"messages": post_menu})

    post_menu = Caterer().post_menu(request.form.get('meal_id'), request.form.get('meal_name'),
                                   request.form.get('price'), request.form.get('category'), request.form.get('day'))
    return jsonify({"messages": post_menu})
示例#3
0
def add_meal(active_user):
    '''Add meal'''
    if not active_user['admin']:
        return 'Only available for Admin!'

    if request.json:
        new_meal = Caterer().post_meal(request.json['meal_id'], request.json['meal_name'],
                                   request.json['price'], request.json['category'], request.json['day'])
        return jsonify({"message": new_meal})

    new_meal = Caterer().post_meal(request.form.get('meal_id'), request.form.get('meal_name'),
                                   request.form.get('price'), request.form.get('category'), request.form.get('day'))
    return jsonify({"message": new_meal})
    def test_edit_meal(self):
        '''Modify meal (PUT)'''
        #Creating a new meal
        Caterer().post_meal(1, "Chicken", 200, "dinner", "Monday")

        #Check if meal doesn't exists
        # results = Caterer().modify_meal(2, "beef", 200, "dinner", "Tuesday")
        # self.assertEqual(results, 'Meal unavailable!', msg='The meal does not exist exists')

        #Modify meal
        results = Caterer().modify_meal(1, "beef", 200, "dinner", "Tuesday")
        self.assertEqual(results,
                         'Meal modification successful',
                         msg='The meal was modified successfully')
    def test_post_menu(self):
        '''Add meal to menu (POST)'''
        #Check empty values are accepted
        results = Caterer().post_menu(4, '', 250, '', "Monday")
        self.assertEqual(results,
                         'Please enter all the details',
                         msg='There is an empty input')

        #Post a menu
        results1 = Caterer().post_menu(5, "Ugali", 300, "lunch", "Monday")
        self.assertEqual(results1, 'Meal successfully added to menu')

        #Check if it's in the menu
        results2 = Caterer().post_menu(5, "Ugali", 300, "lunch", "Monday")
        self.assertEqual(results2, 'Meal exists in menu!')
示例#6
0
def get_all_meals(active_user):
    '''Get all the meals'''
    if not active_user['admin']:
        return 'Only available for Admin!'

    get_meals = Caterer().get_meals()
    return jsonify({"messages": get_meals})
示例#7
0
def get_all_orders(active_user):
    '''Get orders'''
    if not active_user['admin']:
        return 'Only available for Admin!'

    get_order = Caterer().get_orders()
    return jsonify({"messages": get_order})
示例#8
0
def delete_meals(active_user, mealId):
    '''Delete meal'''
    if not active_user['admin']:
        return 'Only available for Admin!'

    delete_meal = Caterer().delete_ml(mealId)
    return jsonify({"message": delete_meal})
    def test_get_menu(self):
        '''Get menu for the day (GET)'''
        #Post menu
        Caterer().post_menu(6, "Ugali", 300, "lunch", "Monday")

        results = User().get_menu()
        self.assertIsInstance(results, list, msg='Incorrect output type')
示例#10
0
    def test_delete_meal(self):
        '''Delete one meal (DELETE)'''
        #Creating a new meal
        Caterer().post_meal(3, "Chicken", 200, "dinner", "Monday")

        #Check if meal doesn't exists
        results = Caterer().delete_ml(2)
        self.assertEqual(results,
                         'Meal unavailable!',
                         msg='The meal does not exist exists')

        #Modify meal
        results = Caterer().delete_ml(3)
        self.assertEqual(results,
                         'Meal Deleted successfully',
                         msg='The meal was deleted successfully')
示例#11
0
    def test_post_meal(self):
        '''Add meal (POST)'''
        #Test if any of the entered values are empty
        results = Caterer().post_meal(1, "", 200, "", "Friday")
        self.assertEqual(results,
                         'Please enter all the details',
                         msg='There is an empty input')

        #Creating a new meal
        results1 = Caterer().post_meal(1, "Kukutu", 200, "dinner", "Friday")
        self.assertEqual(results1,
                         'Meal successfully created',
                         msg='Successful addition of meal')

        #Checking if the meal already exists
        results2 = Caterer().post_meal(1, "Kukutu", 200, "dinner", "Friday")
        self.assertEqual(results2,
                         'Meal exists!',
                         msg='The meal already exists')
示例#12
0
    def test_remove_order(self):
        '''Remove a meal from the user's order list (DELETE)'''
        Caterer().post_menu(8, "Ugali", 250, "lunch", "Monday")
        User().make_order(8, "Ugali", 250, "lunch", "Monday", 1, "ian")

        #Check if meal exists
        results = User().remove_order(3)
        self.assertEqual(results, 'Meal doesn\'t exists in orders!')

        #Modify meal
        results = User().remove_order(8)
        self.assertEqual(results, 'Order removed successfully')
示例#13
0
    def test_modify_order(self):
        '''Modify a certain order (PUT)'''
        Caterer().post_menu(7, "Ugali", 250, "lunch", "Monday")
        User().make_order(7, "Ugali", 250, "lunch", "Monday", 1, "ian")

        #Check if meal exists
        results = User().modify_order(3, 3)
        self.assertEqual(results, 'Meal doesn\'t exists in orders!')

        #Modify meal
        results = User().modify_order(7, 3)
        self.assertEqual(results, 'Order successfully modified')
示例#14
0
 def test_get_meal(self):
     '''Get meal (GET)'''
     Caterer().post_meal(1, "Kuku", 200, "lunch", "Friday")
     results = Caterer().get_meals()
     self.assertIsInstance(results, list, msg='Incorrect output type')
示例#15
0
 def test_make_order(self):
     '''Make order from a chosen meal (POST)'''
     Caterer().post_menu(4, "Ugali", 250, "lunch", "Monday")
     results = User().make_order(4, "Ugali", 250, "lunch", "Monday", 1,
                                 "ian")
     self.assertEqual(results, 'Meal successfully added to your orders')
示例#16
0
 def test_get_orders(self):
     '''Get specific meal orders(GET)'''
     Caterer().post_menu(4, "Ugali", 250, "lunch", "Monday")
     User().make_order(4, "Ugali", 250, "lunch", "Monday", 1, "ian")
     results = Caterer().get_orders()
     self.assertIsInstance(results, list, msg='Incorrect output type')