diff --git a/.coverage b/.coverage new file mode 100644 index 000000000..428a0c501 Binary files /dev/null and b/.coverage differ diff --git a/burger.py b/burger.py index 2b3b6a88b..3f71aaa29 100644 --- a/burger.py +++ b/burger.py @@ -1,7 +1,7 @@ from typing import List -from praktikum.bun import Bun -from praktikum.ingredient import Ingredient +from bun import Bun +from ingredient import Ingredient class Burger: diff --git a/coverage.xml b/coverage.xml new file mode 100644 index 000000000..70e0844b4 --- /dev/null +++ b/coverage.xml @@ -0,0 +1,276 @@ + + + + + + D:\Mistral\QA\ЯПАвто\projects\Project\Task_1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/database.py b/database.py index 4c75baf71..84d3685d0 100644 --- a/database.py +++ b/database.py @@ -1,8 +1,8 @@ from typing import List -from praktikum.bun import Bun -from praktikum.ingredient import Ingredient -from praktikum.ingredient_types import INGREDIENT_TYPE_SAUCE, INGREDIENT_TYPE_FILLING +from bun import Bun +from ingredient import Ingredient +from ingredient_types import INGREDIENT_TYPE_SAUCE, INGREDIENT_TYPE_FILLING class Database: diff --git a/tests/test_bun.py b/tests/test_bun.py new file mode 100644 index 000000000..9815046ba --- /dev/null +++ b/tests/test_bun.py @@ -0,0 +1,51 @@ +import pytest + +import sys +import os +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) + +from bun import Bun + + +class TestBun: + + @pytest.mark.parametrize( + "name, price", + [ + ("black bun", 100.0), + ("white bun", 50.5), + ("sesame bun", 0), + ("", 10.0), + ] + ) + def test_bun_initialization(self, name, price): + bun = Bun(name, price) + + assert bun.name == name + assert bun.price == price + + @pytest.mark.parametrize( + "name", + [ + "black bun", + "white bun", + "", + ] + ) + def test_get_name_returns_correct_name(self, name): + bun = Bun(name, 100.0) + + assert bun.get_name() == name + + @pytest.mark.parametrize( + "price", + [ + 100.0, + 50.5, + 0, + ] + ) + def test_get_price_returns_correct_price(self, price): + bun = Bun("test bun", price) + + assert bun.get_price() == price \ No newline at end of file diff --git a/tests/test_burger.py b/tests/test_burger.py new file mode 100644 index 000000000..932015559 --- /dev/null +++ b/tests/test_burger.py @@ -0,0 +1,82 @@ +import pytest +from unittest.mock import Mock + +import sys +import os +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) +from burger import Burger + + +class TestBurger: + + @pytest.mark.parametrize("bun_price, ingredient_prices, expected_price", [ + (100, [], 200), + (100, [50], 250), + (100, [50, 25], 275), + (0, [10, 20], 30), + ]) + def test_get_price(self, bun_price, ingredient_prices, expected_price): + burger = Burger() + + bun = Mock() + bun.get_price.return_value = bun_price + burger.set_buns(bun) + + for price in ingredient_prices: + ingredient = Mock() + ingredient.get_price.return_value = price + burger.add_ingredient(ingredient) + + assert burger.get_price() == expected_price + + + @pytest.mark.parametrize("index, new_index, expected_order", [ + (0, 2, [2, 3, 1]), + (2, 0, [3, 1, 2]), + (1, 1, [1, 2, 3]), + ]) + def test_move_ingredient(self, index, new_index, expected_order): + burger = Burger() + + ingredients = [] + for i in [1, 2, 3]: + ingredient = Mock() + ingredient.get_name.return_value = str(i) + ingredients.append(ingredient) + burger.add_ingredient(ingredient) + + burger.move_ingredient(index, new_index) + + result_order = [int(i.get_name()) for i in burger.ingredients] + + assert result_order == expected_order + + + @pytest.mark.parametrize("ingredient_type, expected_type", [ + ("SAUCE", "sauce"), + ("FILLING", "filling"), + ]) + def test_get_receipt(self, ingredient_type, expected_type): + 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 = ingredient_type + ingredient.get_name.return_value = "ketchup" + ingredient.get_price.return_value = 50 + burger.add_ingredient(ingredient) + + receipt = burger.get_receipt() + + expected_receipt = ( + "(==== black bun ====)\n" + f"= {expected_type} ketchup =\n" + "(==== black bun ====)\n\n" + "Price: 250" + ) + + assert receipt == expected_receipt \ No newline at end of file diff --git a/tests/test_database.py b/tests/test_database.py new file mode 100644 index 000000000..933b92d1a --- /dev/null +++ b/tests/test_database.py @@ -0,0 +1,43 @@ +import pytest + +import sys +import os +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) +from database import Database +from bun import Bun +from ingredient import Ingredient +from ingredient_types import INGREDIENT_TYPE_SAUCE, INGREDIENT_TYPE_FILLING + + +class TestDatabase: + + def test_available_buns_returns_all_buns(self): + db = Database() + buns = db.available_buns() + + assert isinstance(buns, list) + assert all(isinstance(bun, Bun) for bun in buns) + assert len(buns) == 3 + + names_prices = [(bun.get_name(), bun.get_price()) for bun in buns] + expected = [("black bun", 100), ("white bun", 200), ("red bun", 300)] + assert names_prices == expected + + def test_available_ingredients_returns_all_ingredients(self): + db = Database() + ingredients = db.available_ingredients() + + assert isinstance(ingredients, list) + assert all(isinstance(ing, Ingredient) for ing in ingredients) + assert len(ingredients) == 6 + + types_names_prices = [(ing.get_type(), ing.get_name(), ing.get_price()) for ing in ingredients] + expected = [ + (INGREDIENT_TYPE_SAUCE, "hot sauce", 100), + (INGREDIENT_TYPE_SAUCE, "sour cream", 200), + (INGREDIENT_TYPE_SAUCE, "chili sauce", 300), + (INGREDIENT_TYPE_FILLING, "cutlet", 100), + (INGREDIENT_TYPE_FILLING, "dinosaur", 200), + (INGREDIENT_TYPE_FILLING, "sausage", 300), + ] + assert types_names_prices == expected \ No newline at end of file diff --git a/tests/test_ingredient.py b/tests/test_ingredient.py new file mode 100644 index 000000000..9d1e63095 --- /dev/null +++ b/tests/test_ingredient.py @@ -0,0 +1,42 @@ +import pytest +import sys +import os +sys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), ".."))) +from ingredient import Ingredient + + +class TestIngredient: + + @pytest.mark.parametrize("ingredient_type, name, price", [ + ("SAUCE", "ketchup", 50), + ("FILLING", "cheese", 100), + ("SAUCE", "", 0), + ("FILLING", "bacon", 99.9), + ]) + def test_ingredient_initialization(self, ingredient_type, name, price): + ingredient = Ingredient(ingredient_type, name, price) + + assert ingredient.type == ingredient_type + assert ingredient.name == name + assert ingredient.price == price + + + @pytest.mark.parametrize("price", [0, 10, 99.9]) + def test_get_price(self, price): + ingredient = Ingredient("SAUCE", "test", price) + + assert ingredient.get_price() == price + + + @pytest.mark.parametrize("name", ["ketchup", "cheese", ""]) + def test_get_name(self, name): + ingredient = Ingredient("SAUCE", name, 50) + + assert ingredient.get_name() == name + + + @pytest.mark.parametrize("ingredient_type", ["SAUCE", "FILLING"]) + def test_get_type(self, ingredient_type): + ingredient = Ingredient(ingredient_type, "test", 50) + + assert ingredient.get_type() == ingredient_type \ No newline at end of file