def test_get_sandwich_remove_ingredient(self): sandwich = Sandwich.get_by_id(1) Sandwich.remove_ingredient(1, 2) ingredients = Sandwich.sandwich_ingredients(sandwich) self.assertEqual(len(ingredients), 2)
def edit_submit(request): if request.POST: id = request.POST.get('id') name = request.POST.get('name') ingredient_list = request.POST.get('ingredient_list') profit = request.POST.get('percent') if name or ingredient_list or profit: list = ingredient_list.split(',') sandwich = Sandwich.update(id, name, profit, list) if sandwich is None: messages.error(request, "Erro ao atualizar o lanche") else: if profit is None: messages.error(request, "Percentual de lucro nao pode estar vazio") if ingredient_list is None: messages.error(request, "Lista de ingredientes vazia") if name is None: messages.error(request, "Nome nao pode estar vazio") return redirect('/sandwich/edit/{}'.format(id)) else: messages.error(request, "Erro no rest") return redirect('/sandwich/list')
def create_submit(request): if request.POST: name = request.POST.get('name') ingredient_list = request.POST.get('ingredient_list') profit = request.POST.get('percent') if name: if ingredient_list: if profit: list = ingredient_list.split(',') sandwich = Sandwich.create(name, profit, list) if sandwich is None: messages.error(request, "Erro ao cadastrar o lanche") else: messages.error(request, "Percentual de lucro nao pode estar vazio") else: messages.error(request, "Lista de ingredientes vazia") else: messages.error(request, "Nome nao pode estar vazio") else: messages.error(request, "Erro no rest") return redirect('/sandwich/create')
def create(request): dados = { 'title': 'Novo pedido', 'header': 'Novo pedido', 'icon': 'fas fa-hamburger', 'sandwichs': Sandwich.get_all() } return render(request, 'purchase/create.html', dados)
def setUp(self): ingredient = Ingredient.create("Pão") Ingredient.set_value(ingredient, 1.25) ingredient = Ingredient.create("Hamburger") Ingredient.set_value(ingredient, 1) ingredient = Ingredient.create("Bacon") Ingredient.set_value(ingredient, 2) name = "X-Bacon" list = ["Pão", "Hamburger", "Bacon"] profit = 5.5 sandwich = Sandwich.create(name, profit, list) beverage = Beverage.create("Coca-cola", "2 Litros", 6)
def get_all_open(): purchases = models.Purchase.objects.filter(open=True) for item in purchases: sandwichs = models.SandwichOrder.objects.filter(purchase=item) price = 0 for sandwich in sandwichs: price = price + Sandwich.sandwich_price(sandwich.sandwich) item.price = round(price) return purchases
def edit(request, id): if id: dados = { 'title': 'Editar lanche', 'header': 'Editar lanche', 'icon': 'fas fa-hamburger', 'sandwich': Sandwich.get_by_id(id), 'ingredients': Ingredient.get_all_with_price() } return render(request, 'sandwich/create.html', dados) else: messages.error(request, "ID nao encontrado") return redirect('/sandwich/list')
def remove_ingredient(request, sandwich_id, ingredient_id): if sandwich_id: if ingredient_id: response = Sandwich.remove_ingredient(sandwich_id, ingredient_id) if response is None: messages.error(request, "Erro ao atualizar o lanche") return redirect('/sandwich/edit/{}'.format(sandwich_id)) else: messages.error(request, "Ingrediente não encontrado") else: messages.error(request, "Lanche não encontrado") return redirect('/sandwich/list')
def filter_submit(request): if request.GET: search = request.GET.get("search") if search: sandwich = Sandwich.filter(search) if len(sandwich) > 0: return return_list(request, sandwich) else: messages.error(request, 'lanche não encontrado') else: messages.error(request, 'Busca esta vazia') else: messages.error(request, 'Erro durante a solicitação') return redirect('/sandwich/filter')
def try_create(list): if len(list) > 0: code_id = 1 code = models.Purchase.objects.all().last() if code is not None: code_id = code.id + 1 purchase = models.Purchase.objects.create(code=code_id, date=datetime.date.today()) for item in list: name = item.split(' - ') sandwich = Sandwich.get_by_name(name[0]) models.SandwichOrder.objects.create(sandwich=sandwich, purchase=purchase) return purchase else: return None
def test_get_sandwich_by_id(self): sandwich = Sandwich.get_by_id(1) self.assertIsNotNone(sandwich)
def test_get_sandwich_add_profit(self): sandwich = Sandwich.get_by_id(1) Sandwich.add_profit(sandwich, 3.5) profit = Sandwich.get_profit(sandwich) self.assertEqual(profit.percent, 3.5)
def test_create_sandwich(self): name = "X-burger" list = ["Pão","Hamburger"] profit = 5.5 sandwich = Sandwich.create(name, profit, list) self.assertEqual(sandwich.id, 2)
def test_get_all_sandwich(self): sandwich = Sandwich.get_all() self.assertIsNotNone(sandwich)
def list(request): return return_list(request, Sandwich.get_all())
def test_filter_sandwich_ingredient(self): sandwich = Sandwich.filter("Hamburger") self.assertNotEqual(len(sandwich), 0)
def test_filter_sandwich_name(self): sandwich = Sandwich.filter("X") self.assertNotEqual(len(sandwich), 0)
def test_get_sandwich_update_name(self): Sandwich.update_name(1, "X bacon") sandwich = Sandwich.get_by_id(1) self.assertEqual(sandwich.name, "X bacon")
def test_get_sandwich_update(self): list = ["bacon"] Sandwich.update(1, "X-bacon", 10, list) sandwich = Sandwich.get_by_id(1) self.assertEqual(sandwich.name, "X-bacon")