From 8eaf6fa5c142f469deefcfde95c9fe49827b31a1 Mon Sep 17 00:00:00 2001 From: Evgeniya Date: Fri, 12 Jun 2026 13:25:29 +0300 Subject: [PATCH 1/2] =?UTF-8?q?=D0=94=D0=B8=D0=BF=D0=BB=D0=BE=D0=BC=5F1:?= =?UTF-8?q?=20=D1=8E=D0=BD=D0=B8=D1=82-=D1=82=D0=B5=D1=81=D1=82=D1=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- conftest.py | 58 +++++ data.py | 81 +++++++ htmlcov/index.html | 213 ++++++++++++++++++ __init__.py => praktikum/__init__.py | 0 bun.py => praktikum/bun.py | 0 burger.py => praktikum/burger.py | 0 database.py => praktikum/database.py | 0 ingredient.py => praktikum/ingredient.py | 0 .../ingredient_types.py | 0 requirements.txt | Bin 0 -> 66 bytes tests/test_bun.py | 17 ++ tests/test_burger.py | 70 ++++++ tests/test_database.py | 55 +++++ tests/test_ingredient.py | 27 +++ 14 files changed, 521 insertions(+) create mode 100644 conftest.py create mode 100644 data.py create mode 100644 htmlcov/index.html rename __init__.py => praktikum/__init__.py (100%) rename bun.py => praktikum/bun.py (100%) rename burger.py => praktikum/burger.py (100%) rename database.py => praktikum/database.py (100%) rename ingredient.py => praktikum/ingredient.py (100%) rename ingredient_types.py => praktikum/ingredient_types.py (100%) create mode 100644 requirements.txt create mode 100644 tests/test_bun.py create mode 100644 tests/test_burger.py create mode 100644 tests/test_database.py create mode 100644 tests/test_ingredient.py diff --git a/conftest.py b/conftest.py new file mode 100644 index 000000000..acc807125 --- /dev/null +++ b/conftest.py @@ -0,0 +1,58 @@ +import pytest +from unittest.mock import Mock +from praktikum.burger import Burger +from praktikum.database import Database +from data import * + +@pytest.fixture +def burger(): + return Burger() + +@pytest.fixture +def database(): + return Database() + +@pytest.fixture +def mock_bun(): + """Создание мок-булочки с базовыми данными.""" + mock = Mock() + mock.get_name.return_value = TEST_BUN["name"] + mock.get_price.return_value = TEST_BUN["price"] + return mock + +def _create_mock_ingredient(type, name, price): + """Вспомогательная функция для создания мок-ингредиента.""" + mock = Mock() + mock.get_type.return_value = type + mock.get_name.return_value = name + mock.get_price.return_value = price + return mock + +@pytest.fixture +def mock_sauce(): + """Мок соуса.""" + return _create_mock_ingredient(**TEST_SAUCE) + +@pytest.fixture +def mock_filling(): + """Мок начинки.""" + return _create_mock_ingredient(**TEST_FILLING_1) + +@pytest.fixture +def mock_ingredients(mock_sauce, mock_filling): + """Список базовых ингредиентов.""" + return [mock_sauce, mock_filling] + +@pytest.fixture +def burger_with_bun(burger, mock_bun): + """Бургер с установленной булочкой.""" + burger.set_buns(mock_bun) + return burger + +@pytest.fixture +def full_burger(burger_with_bun, mock_ingredients): + """Полностью собранный бургер (булочка + ингредиенты).""" + for ingredient in mock_ingredients: + burger_with_bun.add_ingredient(ingredient) + return burger_with_bun + diff --git a/data.py b/data.py new file mode 100644 index 000000000..aeb0273ac --- /dev/null +++ b/data.py @@ -0,0 +1,81 @@ +from praktikum.ingredient_types import INGREDIENT_TYPE_SAUCE, INGREDIENT_TYPE_FILLING +from praktikum.bun import Bun +from praktikum.ingredient import Ingredient + +TEST_BUN_DATA = { + "names": [ + ("black bun", "black bun"), + ("булочка", "булочка"), + ("a", "a"), + ], + "prices": [ + (300.0, 300.0), + (350.50, 350.50), + (2, 2), + ] +} + +TEST_INGREDIENT_DATA = { + "types": [ + (INGREDIENT_TYPE_SAUCE, INGREDIENT_TYPE_SAUCE), + (INGREDIENT_TYPE_FILLING, INGREDIENT_TYPE_FILLING), + ], + "names": [ + ("соус", "соус"), + ("ingredient", "ingredient"), + ], + "prices": [ + (100.0, 100.0), + (0, 0), + (350.50, 350.50), + ] +} + +TEST_BUN = { + "name": "Булочка с кунжутом", + "price": 50.0 +} +TEST_BUN_2 = { + "name": "Космическая булочка", + "price": 150.0 +} + +TEST_SAUCE = { + "type": INGREDIENT_TYPE_SAUCE, + "name": "Кетчуп", + "price": 20.0 + } +TEST_FILLING_1 = { + "type": INGREDIENT_TYPE_FILLING, + "name": "Котлета гриль", + "price": 150.0 + } + +TEST_FILLING_2 = { + "type": INGREDIENT_TYPE_FILLING, + "name": "Сыр", + "price": 80.0 + } + +RECEIPT_TEMPLATE = ( + "(==== {bun} ====)\n" + "= sauce {sauce} =\n" + "= filling {filling} =\n" + "(==== {bun} ====)\n" + "\n" + "Price: {price}" +) +EXPECTED_BUNS = [ + Bun("black bun", 100), + Bun("white bun", 200), + Bun("red bun", 300) +] + +EXPECTED_INGREDIENTS = [ + Ingredient(INGREDIENT_TYPE_SAUCE, "hot sauce", 100), + Ingredient(INGREDIENT_TYPE_SAUCE, "sour cream", 200), + Ingredient(INGREDIENT_TYPE_SAUCE, "chili sauce", 300), + Ingredient(INGREDIENT_TYPE_FILLING, "cutlet", 100), + Ingredient(INGREDIENT_TYPE_FILLING, "dinosaur", 200), + Ingredient(INGREDIENT_TYPE_FILLING, "sausage", 300) +] \ No newline at end of file diff --git a/htmlcov/index.html b/htmlcov/index.html new file mode 100644 index 000000000..df8db7fbb --- /dev/null +++ b/htmlcov/index.html @@ -0,0 +1,213 @@ + + + + + Coverage report + + + + + +
+
+

Coverage report: + 100% +

+ +
+ +
+ + +
+
+

+ Files + Functions + Classes +

+

+ coverage.py v7.14.1, + created at 2026-06-06 19:20 +0300 +

+
+
+
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
  Statements Branches Total
File coveragestatementsmissingexcluded coveragebranchespartial coverage
praktikum\__init__.py 100%000 100%00 100%
praktikum\bun.py 100%800 100%00 100%
praktikum\burger.py 100%2700 100%40 100%
praktikum\database.py 100%2100 100%00 100%
praktikum\ingredient.py 100%1100 100%00 100%
praktikum\ingredient_types.py 100%200 100%00 100%
Total 100%6900 100%40 100%
+

+ No items found using the specified filter. +

+
+ + + diff --git a/__init__.py b/praktikum/__init__.py similarity index 100% rename from __init__.py rename to praktikum/__init__.py diff --git a/bun.py b/praktikum/bun.py similarity index 100% rename from bun.py rename to praktikum/bun.py diff --git a/burger.py b/praktikum/burger.py similarity index 100% rename from burger.py rename to praktikum/burger.py diff --git a/database.py b/praktikum/database.py similarity index 100% rename from database.py rename to praktikum/database.py diff --git a/ingredient.py b/praktikum/ingredient.py similarity index 100% rename from ingredient.py rename to praktikum/ingredient.py diff --git a/ingredient_types.py b/praktikum/ingredient_types.py similarity index 100% rename from ingredient_types.py rename to praktikum/ingredient_types.py diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000000000000000000000000000000000000..c3362913e92d0fd18e60247989bee458677decc7 GIT binary patch literal 66 zcmezWuYjSFp@boop%_To0-+^?9)kf88#C}Sa4{gu>M|rV 0 + + def test_available_buns_count(self, database): + """Количество булочек""" + result = database.available_buns() + assert len(result) == 3 + + def test_available_ingredients_returns_list(self, database): + """Метод available_ingredients возвращает список""" + result = database.available_ingredients() + assert isinstance(result, list) + + def test_available_ingredients_not_empty(self, database): + """Список ингредиентов не пустой""" + result = database.available_ingredients() + assert len(result) > 0 + + def test_available_ingredients_count(self, database): + """Количество ингредиентов""" + result = database.available_ingredients() + assert len(result) == 6 + + @pytest.mark.parametrize("expected_bun", EXPECTED_BUNS) + def test_available_buns_contains_expected(self, database, expected_bun): + """Проверяет, что каждая ожидаемая булочка присутствует""" + buns = database.available_buns() + assert any( + bun.get_name() == expected_bun.get_name() and + bun.get_price() == expected_bun.get_price() + for bun in buns + ) + + @pytest.mark.parametrize("expected_ingredient", EXPECTED_INGREDIENTS) + def test_available_ingredients_contains_expected(self, database, expected_ingredient): + """Проверяет, что каждый ожидаемый ингредиент присутствует""" + ingredients = database.available_ingredients() + assert any( + ingredient.get_type() == expected_ingredient.get_type() and + ingredient.get_name() == expected_ingredient.get_name() and + ingredient.get_price() == expected_ingredient.get_price() + for ingredient in ingredients + ) \ No newline at end of file diff --git a/tests/test_ingredient.py b/tests/test_ingredient.py new file mode 100644 index 000000000..753aa29e1 --- /dev/null +++ b/tests/test_ingredient.py @@ -0,0 +1,27 @@ +import pytest +from praktikum.ingredient import Ingredient +from praktikum.ingredient_types import INGREDIENT_TYPE_SAUCE +from data import TEST_INGREDIENT_DATA + +class TestIngredient: + + @pytest.mark.parametrize("ingredient_type, expected_type", TEST_INGREDIENT_DATA["types"]) + def test_get_type_returns_correct_type(self, ingredient_type, expected_type): + """Метод get_type возвращает правильный тип.""" + ingredient = Ingredient(ingredient_type, "Название ингридиента", 100.0) + assert ingredient.get_type() == expected_type + + @pytest.mark.parametrize("name, expected_name", TEST_INGREDIENT_DATA["names"]) + def test_get_name_returns_correct_name(self, name, expected_name): + """Метод get_name возвращает правильное имя.""" + ingredient = Ingredient(INGREDIENT_TYPE_SAUCE, name, 100.0) + assert ingredient.get_name() == expected_name + + @pytest.mark.parametrize("price, expected_price", TEST_INGREDIENT_DATA["prices"]) + def test_get_price_returns_correct_price(self, price, expected_price): + """Метод get_price возвращает правильную цену.""" + ingredient = Ingredient(INGREDIENT_TYPE_SAUCE, "Название ингридиента", price) + assert ingredient.get_price() == expected_price + + + From fe12e0781b84be1629d040763f9de5b758f1c20e Mon Sep 17 00:00:00 2001 From: Evgeniya Date: Sat, 13 Jun 2026 16:28:27 +0300 Subject: [PATCH 2/2] =?UTF-8?q?=D0=94=D0=B8=D0=BF=D0=BB=D0=BE=D0=BC=5F1:?= =?UTF-8?q?=20=D1=8E=D0=BD=D0=B8=D1=82-=D1=82=D0=B5=D1=81=D1=82=D1=8B=20-?= =?UTF-8?q?=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB=D0=B5=D0=BD=D0=B8?= =?UTF-8?q?=D1=8F=20=D0=B7=D0=B0=D0=BC=D0=B5=D1=87=D0=B0=D0=BD=D0=B8=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- conftest.py | 51 +++-------- helpers.py | 9 ++ htmlcov/index.html | 213 --------------------------------------------- 3 files changed, 19 insertions(+), 254 deletions(-) create mode 100644 helpers.py delete mode 100644 htmlcov/index.html diff --git a/conftest.py b/conftest.py index acc807125..21c54d6a0 100644 --- a/conftest.py +++ b/conftest.py @@ -1,7 +1,7 @@ import pytest -from unittest.mock import Mock from praktikum.burger import Burger from praktikum.database import Database +from helpers import create_mock_ingredient from data import * @pytest.fixture @@ -13,46 +13,15 @@ def database(): return Database() @pytest.fixture -def mock_bun(): - """Создание мок-булочки с базовыми данными.""" - mock = Mock() - mock.get_name.return_value = TEST_BUN["name"] - mock.get_price.return_value = TEST_BUN["price"] - return mock +def full_burger(): + """Полностью собранный бургер.""" + burger = Burger() + bun = create_mock_ingredient("bun", TEST_BUN["name"], TEST_BUN["price"]) + sauce = create_mock_ingredient(**TEST_SAUCE) + filling = create_mock_ingredient(**TEST_FILLING_1) -def _create_mock_ingredient(type, name, price): - """Вспомогательная функция для создания мок-ингредиента.""" - mock = Mock() - mock.get_type.return_value = type - mock.get_name.return_value = name - mock.get_price.return_value = price - return mock - -@pytest.fixture -def mock_sauce(): - """Мок соуса.""" - return _create_mock_ingredient(**TEST_SAUCE) - -@pytest.fixture -def mock_filling(): - """Мок начинки.""" - return _create_mock_ingredient(**TEST_FILLING_1) - -@pytest.fixture -def mock_ingredients(mock_sauce, mock_filling): - """Список базовых ингредиентов.""" - return [mock_sauce, mock_filling] - -@pytest.fixture -def burger_with_bun(burger, mock_bun): - """Бургер с установленной булочкой.""" - burger.set_buns(mock_bun) + burger.set_buns(bun) + burger.add_ingredient(sauce) + burger.add_ingredient(filling) return burger -@pytest.fixture -def full_burger(burger_with_bun, mock_ingredients): - """Полностью собранный бургер (булочка + ингредиенты).""" - for ingredient in mock_ingredients: - burger_with_bun.add_ingredient(ingredient) - return burger_with_bun - diff --git a/helpers.py b/helpers.py new file mode 100644 index 000000000..5eca79109 --- /dev/null +++ b/helpers.py @@ -0,0 +1,9 @@ +from unittest.mock import Mock + +def create_mock_ingredient(type, name, price): + """Вспомогательная функция для создания мок-ингредиента.""" + mock = Mock() + mock.get_type.return_value = type + mock.get_name.return_value = name + mock.get_price.return_value = price + return mock \ No newline at end of file diff --git a/htmlcov/index.html b/htmlcov/index.html deleted file mode 100644 index df8db7fbb..000000000 --- a/htmlcov/index.html +++ /dev/null @@ -1,213 +0,0 @@ - - - - - Coverage report - - - - - -
-
-

Coverage report: - 100% -

- -
- -
- - -
-
-

- Files - Functions - Classes -

-

- coverage.py v7.14.1, - created at 2026-06-06 19:20 +0300 -

-
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  Statements Branches Total
File coveragestatementsmissingexcluded coveragebranchespartial coverage
praktikum\__init__.py 100%000 100%00 100%
praktikum\bun.py 100%800 100%00 100%
praktikum\burger.py 100%2700 100%40 100%
praktikum\database.py 100%2100 100%00 100%
praktikum\ingredient.py 100%1100 100%00 100%
praktikum\ingredient_types.py 100%200 100%00 100%
Total 100%6900 100%40 100%
-

- No items found using the specified filter. -

-
- - -