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 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 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)