Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .coverage
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[pytest]
pythonpath = .
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pytest
pytest-cov
11 changes: 11 additions & 0 deletions tests/test_bun.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from praktikum.bun import Bun

class TestBun:

def test_get_name(self):
bun = Bun("black bun", 100)
assert bun.get_name() == "black bun"

def test_get_price(self):
bun = Bun("black bun", 100)
assert bun.get_price() == 100
94 changes: 94 additions & 0 deletions tests/test_burger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import pytest
from unittest.mock import Mock
from praktikum.burger import Burger


class TestBurger:

def test_set_buns(self):
burger = Burger()
bun = Mock()

burger.set_buns(bun)

assert burger.bun == bun

def test_add_ingredient(self):
burger = Burger()
ingredient = Mock()

burger.add_ingredient(ingredient)

assert ingredient in burger.ingredients
assert len(burger.ingredients) == 1

def test_remove_ingredient(self):
burger = Burger()
ingredient = Mock()

burger.add_ingredient(ingredient)
burger.remove_ingredient(0)

assert len(burger.ingredients) == 0

def test_move_ingredient(self):
burger = Burger()

ing1 = Mock()
ing2 = Mock()

burger.add_ingredient(ing1)
burger.add_ingredient(ing2)

burger.move_ingredient(0, 1)

assert burger.ingredients[0] == ing2
assert burger.ingredients[1] == ing1

@pytest.mark.parametrize(
"bun_price, ing_prices, expected_total",
[
(100, [50, 70], 320),
(200, [], 400),
(50, [25, 25, 50], 200)
]
)
def test_get_price(self, bun_price, ing_prices, expected_total):
burger = Burger()

bun = Mock()
bun.get_price.return_value = bun_price
burger.set_buns(bun)

for price in ing_prices:
ingredient = Mock()
ingredient.get_price.return_value = price
burger.add_ingredient(ingredient)

assert burger.get_price() == expected_total

def test_get_receipt(self):
burger = Burger()

bun = Mock()
bun.get_name.return_value = "black bun"
bun.get_price.return_value = 100
burger.set_buns(bun)

ingredient = Mock()
ingredient.get_type.return_value = "SAUCE"
ingredient.get_name.return_value = "hot sauce"
ingredient.get_price.return_value = 50
burger.add_ingredient(ingredient)

receipt = burger.get_receipt()

expected_receipt = (
"(==== black bun ====)\n"
"= sauce hot sauce =\n"
"(==== black bun ====)\n"
"\n"
"Price: 250"
)

assert receipt == expected_receipt
19 changes: 19 additions & 0 deletions tests/test_database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from praktikum.database import Database
from praktikum.bun import Bun
from praktikum.ingredient import Ingredient

class TestDatabase:

def test_available_buns(self):
db = Database()
buns = db.available_buns()
assert isinstance(buns, list)
assert all(isinstance(b, Bun) for b in buns)
assert len(buns) == 3

def test_available_ingredients(self):
db = Database()
ingredients = db.available_ingredients()
assert isinstance(ingredients, list)
assert all(isinstance(i, Ingredient) for i in ingredients)
assert len(ingredients) == 6
38 changes: 38 additions & 0 deletions tests/test_ingredient.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import pytest
from praktikum.ingredient import Ingredient
from praktikum.ingredient_types import INGREDIENT_TYPE_SAUCE, INGREDIENT_TYPE_FILLING

class TestIngredient:

@pytest.mark.parametrize(
"ingredient_type,name,price",
[
(INGREDIENT_TYPE_SAUCE, "hot sauce", 100),
(INGREDIENT_TYPE_FILLING, "cutlet", 200)
]
)
def test_get_name(self, ingredient_type, name, price):
ingredient = Ingredient(ingredient_type, name, price)
assert ingredient.get_name() == name

@pytest.mark.parametrize(
"ingredient_type,name,price",
[
(INGREDIENT_TYPE_SAUCE, "hot sauce", 100),
(INGREDIENT_TYPE_FILLING, "cutlet", 200)
]
)
def test_get_price(self, ingredient_type, name, price):
ingredient = Ingredient(ingredient_type, name, price)
assert ingredient.get_price() == price

@pytest.mark.parametrize(
"ingredient_type,name,price",
[
(INGREDIENT_TYPE_SAUCE, "hot sauce", 100),
(INGREDIENT_TYPE_FILLING, "cutlet", 200)
]
)
def test_get_type(self, ingredient_type, name, price):
ingredient = Ingredient(ingredient_type, name, price)
assert ingredient.get_type() == ingredient_type