예제 #1
0
 def testInsertUser(self):
     server = DishHelper("test_dish2")
     for user in insert_dishes:
         result, message = server.add_dish(user['restaurant'],
                                           user['dishname'], user['price'])
         assert result
         assert server.delete_dish(user['restaurant'], user['dishname'])
예제 #2
0
 def testUpdateUser(self):
     server = DishHelper("test_dish2")
     for user in dishes:
         assert server.change_price(user['restaurant'], user['dishname'],
                                    35)
         user_data, message = server.get_dish_price(user['restaurant'],
                                                    user['dishname'])
         assert int(user_data['price']) == 35
         assert server.change_price(user['restaurant'], user['dishname'],
                                    user['price'])
예제 #3
0
class MenuHelper:
    def __init__(self, db_name="DishInfo"):
        self.db = DishHelper(db_name)

    def addDish(self, restaurant, form):
        dishname = form['dishname']
        price = form['price']
        if re.findall(r'[^a-zA-Z-\s]', dishname) or re.findall('[^A-Za-z0-9_]', restaurant):
            return False, "Can't contain special character."
        if not price or price == "":
            return False, "Price not specified!"
        valid, message = self.db.add_dish(restaurant, dishname, price)
        return valid, message

    def getDish(self, restaurant):
        return self.db.get_dish(restaurant)

    def getDishPrice(self, restaurant, dishname):
        dish, message = self.db.get_dish_price(restaurant, dishname)
        return dish

    def deleteDish(self, restaurant, dishname):
        return self.db.delete_dish(restaurant, dishname)

    def add_to_cart(self, session, restaurant, dishname, amount):
        if session['total_dishes'] >= 10:
            return False

        dish = self.getDishPrice(restaurant, dishname)
        if dish:
            price = dish['price']
        else:
            return False

        if restaurant != session['restaurant']:
            session['restaurant'] = restaurant
            session['dishes'] = []
            session['total_dishes'] = 0
            session['total'] = 0.0
        # session['restaurant'] = 'b'
        # print(restaurant, dish_id, session['dishes'], session['total_dishes'])
        i = 0
        while i < len(session['dishes']):
            if dishname == session['dishes'][i][0]:
                break
            i += 1
        if i != len(session['dishes']):
            # print(i)
            session['dishes'][i][2] += amount
        else:
            session['dishes'].append([dishname, price, amount])
        # print("end ", restaurant, dish_id, session['dishes'], session['total_dishes'])
        session['total_dishes'] += 1
        session['total'] += float(price)
        return True
예제 #4
0
 def testGetDishPrice(self):
     server = DishHelper("test_dish2")
     # print (profiles)
     for user in dishes:
         # server.insert(user, user['userid'], user['username'])
         user_data, message = server.get_dish_price(user['restaurant'],
                                                    user['dishname'])
         # print("user_data", user_data)
         # print("user", user)
         assert user_data
         print(user_data, user)
         assert int(user_data['price']) == user['price']
예제 #5
0
 def testServer(self):
     server = DishHelper('test_dish2')
     assert server is not None
예제 #6
0
 def testGetDish(self):
     server = DishHelper("test_dish2")
     assert server.get_dish('a')
     assert server.get_dish('b')
예제 #7
0
 def testFailRegister(self):
     server = DishHelper("test_dish2")
     for dish in manage_fail_dish:
         result, message = server.add_dish(dish['restaurant'],
                                           dish['dishname'], dish['price'])
         assert not result
예제 #8
0
 def __init__(self, db_name="DishInfo"):
     self.db = DishHelper(db_name)