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.
7 changes: 7 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
coverage==7.13.5
iniconfig==2.3.0
packaging==26.0
pluggy==1.6.0
Pygments==2.20.0
pytest==9.0.2
pytest-cov==7.1.0
Empty file added tests/__init__.py
Empty file.
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_bun_price(self):
bun = Bun('Краторная булка N-200i', 1255)
assert bun.get_price() == 1255

def test_get_bun_name(self):
bun = Bun('Краторная булка N-200i', 1255)
assert bun.get_name() == 'Краторная булка N-200i'
73 changes: 73 additions & 0 deletions tests/test_burger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import praktikum.ingredient_types


from unittest.mock import Mock
from praktikum.burger import Burger, Bun
from praktikum.database import Database


class TestBurger:
def test_set_buns_correct(self):
burger = Burger()

bun = Bun('Name_bun', 100.0)
burger.set_buns(bun)

assert burger.bun == bun

def test_add_ingredient_correct(self):
burger = Burger()
mock_ingredient = Mock()

mock_ingredient.get_price.return_value = 9.0
mock_ingredient.get_name.return_value = 'тест'
mock_ingredient.get_type.return_value = praktikum.ingredient_types.INGREDIENT_TYPE_FILLING
burger.add_ingredient(mock_ingredient)

assert burger.ingredients[0].get_type() == praktikum.ingredient_types.INGREDIENT_TYPE_FILLING
assert burger.ingredients[0].get_price() == 9.0
assert burger.ingredients[0].get_name() == 'тест'


def test_remove_ingredient_successful(self):
burger = Burger()
mock_ingredient = Mock()

burger.add_ingredient(mock_ingredient)
burger.remove_ingredient(0)

assert len(burger.ingredients) == 0

def test_get_price_correct(self):
burger = Burger()
base = Database()

burger.set_buns(base.available_buns()[0])
burger.add_ingredient(base.available_ingredients()[0])
burger.add_ingredient(base.available_ingredients()[3])

assert burger.get_price() == 400.0

def test_get_receipt_correct(self):
burger = Burger()
base = Database()

burger.set_buns(base.available_buns()[1])
burger.add_ingredient(base.available_ingredients()[1])
burger.add_ingredient(base.available_ingredients()[3])

expected_receipt = "(==== white bun ====)\n"\
"= sauce sour cream =\n"\
"= filling cutlet =\n"\
"(==== white bun ====)\n\n"\
"Price: 700"
assert expected_receipt == burger.get_receipt()

def test_move_ingredient_forward(self):
burger = Burger()

burger.ingredients = ["bun", "cutlet", "cheese", "sauce"]
burger.move_ingredient(2, 1)
expected = ["bun", "cheese", "cutlet", "sauce"]

assert burger.ingredients == expected
40 changes: 40 additions & 0 deletions tests/test_database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
from praktikum.ingredient_types import INGREDIENT_TYPE_SAUCE, INGREDIENT_TYPE_FILLING
from praktikum.database import Database


class TestDataBase:
def test_get_available_ingredients_correct(self):
data_ingredients = Database()

available_ingredients = data_ingredients.available_ingredients()
assert len(available_ingredients) == 6

def test_get_available_buns_correct(self):
data_bun = Database()

available_buns = data_bun.available_buns()
assert len(available_buns) == 3

def test_get_available_ingredients_prices_correct(self):
data_price = Database()

ingredients = data_price.available_ingredients()
price = {i.get_name(): i.get_price() for i in ingredients}

assert price['hot sauce'] == 100

def test_get_count_available_sauces_correct(self):
count_ingredients = Database()

ingredients = count_ingredients.available_ingredients()
type_sauce = [i for i in ingredients if i.get_type() == INGREDIENT_TYPE_SAUCE]

assert len(type_sauce) == 3

def test_get_count_available_fillings_correct(self):
correct_ingredients = Database()

ingredients = correct_ingredients.available_ingredients()
type_fillings = [i for i in ingredients if i.get_type() == INGREDIENT_TYPE_FILLING]

assert len(type_fillings) == 3
24 changes: 24 additions & 0 deletions tests/test_ingredient.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import pytest
from praktikum.ingredient import Ingredient
from praktikum.ingredient_types import *


class TestIngredient:
def test_get_name_correct_name(self):
ingredient = Ingredient(INGREDIENT_TYPE_SAUCE, 'Соус традиционный галактический', 15)
assert ingredient.get_name() == 'Соус традиционный галактический'

def test_get_price_correct_price(self):
ingredient = Ingredient(INGREDIENT_TYPE_SAUCE, 'Тест', 15)
assert ingredient.get_price() == 15

@pytest.mark.parametrize(
'type, name, price, expected_ingredient',
[
[INGREDIENT_TYPE_SAUCE, 'Соус традиционный галактический', 15, 'SAUCE'],
[INGREDIENT_TYPE_FILLING, 'Хрустящие минеральные кольца', 300, 'FILLING']
]
)
def test_get_type_correct_type(self, name, price, type, expected_ingredient):
ingredient = Ingredient(type, name, price)
assert ingredient.get_type() == expected_ingredient