Skip to content

Commit

Permalink
fix bugs in test_cartepizza class
Browse files Browse the repository at this point in the history
  • Loading branch information
amina-sab committed Mar 6, 2024
1 parent 24abfc7 commit b56d1ca
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 43 deletions.
8 changes: 6 additions & 2 deletions CartePizzeria.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
from CartePizzeriaException import CartePizzeriaException


class CartePizzeria:
def __init__(self):
self.pizzas=[]
Expand All @@ -14,7 +17,8 @@ def add_pizza(self,pizza):
def remove_pizza(self,name):
for p in self.pizzas:
if(p.name==name):
self.pizzas.remove(p)
self.pizzas.remove(p)
return

raise CartePizzeriaException("Pizza not found: " + name)
raise CartePizzeriaException("Pizza not found: " + name)

41 changes: 0 additions & 41 deletions TestsUnitaires.py

This file was deleted.

Binary file added __pycache__/CartePizzeria.cpython-312.pyc
Binary file not shown.
Binary file added __pycache__/CartePizzeriaException.cpython-312.pyc
Binary file not shown.
Binary file not shown.
43 changes: 43 additions & 0 deletions test_cartePizza.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import pytest
from unittest.mock import MagicMock
from CartePizzeria import CartePizzeria
from CartePizzeriaException import CartePizzeriaException

def test_is_empty():
carte_pizza=CartePizzeria()
assert carte_pizza.is_empty()==True

pizza_mock=MagicMock()
carte_pizza.add_pizza(pizza_mock)
assert carte_pizza.is_empty()==False

def test_nb_pizzas():
carte_pizza=CartePizzeria()
assert carte_pizza.nb_pizzas()==0

marguarita=MagicMock()
campionne=MagicMock()
carte_pizza.add_pizza(marguarita)
carte_pizza.add_pizza(campionne)
assert carte_pizza.nb_pizzas()==2

def test_add_pizza():
carte_pizza=CartePizzeria()
campionne=MagicMock()
carte_pizza.add_pizza(campionne)
assert carte_pizza.nb_pizzas()==1

def test_remove_pizza():
carte_pizza=CartePizzeria()
pizza_mock_1=MagicMock()
pizza_mock_1.name="vegetarienne"
pizza_mock_2=MagicMock()
pizza_mock_2.name="marguarita"
carte_pizza.add_pizza(pizza_mock_1)
carte_pizza.add_pizza(pizza_mock_2)

carte_pizza.remove_pizza("vegetarienne")
assert carte_pizza.nb_pizzas()==1

with pytest.raises(CartePizzeriaException):
carte_pizza.remove_pizza("Hawaiiane")

0 comments on commit b56d1ca

Please sign in to comment.