From 6ff1de58def16c028a1ef664204b4b3e4668b327 Mon Sep 17 00:00:00 2001 From: Dmitriy Date: Fri, 15 May 2026 13:33:58 +0300 Subject: [PATCH 1/5] =?UTF-8?q?feat:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D0=BB=20=20=D1=8E=D0=BD=D0=B8=D1=82-=D1=82=D0=B5=D1=81?= =?UTF-8?q?=D1=82=D1=8B=20=D0=B4=D0=BB=D1=8F=20=D0=BA=D0=BB=D0=B0=D1=81?= =?UTF-8?q?=D1=81=D0=B0=20Bun=20=D1=81=20=D0=BF=D0=B0=D1=80=D0=B0=D0=BC?= =?UTF-8?q?=D0=B5=D1=82=D1=80=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D0=B5=D0=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 11 +++++++++++ tests/__init__.py | 0 tests/test_bun.py | 17 +++++++++++++++++ 3 files changed, 28 insertions(+) create mode 100644 .gitignore create mode 100644 tests/__init__.py create mode 100644 tests/test_bun.py diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..6a8063226 --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +# Виртуальное окружение +venv/ +.venv/ + +# Кеш Python +__pycache__/ +*.pyc + +# Отчёты покрытия +.coverage +htmlcov/ \ No newline at end of file diff --git a/tests/__init__.py b/tests/__init__.py new file mode 100644 index 000000000..e69de29bb diff --git a/tests/test_bun.py b/tests/test_bun.py new file mode 100644 index 000000000..09d5ed0a9 --- /dev/null +++ b/tests/test_bun.py @@ -0,0 +1,17 @@ +import pytest +from praktikum.bun import Bun +from data import BUN_PARAMS + +class TestBun: + + @pytest.mark.parametrize('name, price', BUN_PARAMS) + def test_bun_creation(self, name, price): + bun = Bun(name, price) + assert bun.name == name + assert bun.price == price + + def test_get_name(self, bun): + assert bun.get_name() == 'Test Bun' + + def test_get_price(self, bun): + assert bun.get_price() == 100 \ No newline at end of file From 98c38dcad6da8443e7877fc27df43d8aee091959 Mon Sep 17 00:00:00 2001 From: Dmitriy Date: Fri, 15 May 2026 20:16:38 +0300 Subject: [PATCH 2/5] =?UTF-8?q?tests:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D1=82=D1=8C=20=D1=8E=D0=BD=D0=B8=D1=82-=D1=82=D0=B5?= =?UTF-8?q?=D1=81=D1=82=D1=8B=20=D0=B4=D0=BB=D1=8F=20Bun,=20Ingredient=20?= =?UTF-8?q?=D0=B8=20Burger,=20=D1=80=D0=B5=D0=B0=D0=BB=D0=B8=D0=B7=D0=BE?= =?UTF-8?q?=D0=B2=D0=B0=D1=82=D1=8C=20=D0=BF=D0=B0=D1=80=D0=B0=D0=BC=D0=B5?= =?UTF-8?q?=D1=82=D1=80=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8E=20=D1=82=D0=B0?= =?UTF-8?q?=D0=BC,=20=D0=B3=D0=B4=D0=B5=20=D1=8D=D1=82=D0=BE=20=D0=BD?= =?UTF-8?q?=D0=B5=D0=BE=D0=B1=D1=85=D0=BE=D0=B4=D0=B8=D0=BC=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 1 + conftest.py | 34 +++++++++++ data.py | 26 ++++++++ __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 | 2 + tests/test_bun.py | 10 +-- tests/test_burger.py | 61 +++++++++++++++++++ tests/test_ingredient.py | 22 +++++++ 13 files changed, 152 insertions(+), 4 deletions(-) create mode 100644 conftest.py create mode 100644 data.py 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_burger.py create mode 100644 tests/test_ingredient.py diff --git a/.gitignore b/.gitignore index 6a8063226..b614a72b0 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ venv/ # Кеш Python __pycache__/ +.pytest_cache/ *.pyc # Отчёты покрытия diff --git a/conftest.py b/conftest.py new file mode 100644 index 000000000..eee6d3be0 --- /dev/null +++ b/conftest.py @@ -0,0 +1,34 @@ +import pytest +import data as D +from praktikum.bun import Bun +from praktikum.burger import Burger +from praktikum.ingredient import Ingredient + + +@pytest.fixture +def bun(): + bun = Bun(D.BURGER_BUN_NAME, D.BURGER_BUN_PRICE) + return bun + +@pytest.fixture +def filling(): + ingredient = Ingredient( + D.INGREDIENT_TYPE_FILLING, + D.INGREDIENT_FILLING_NAME, + D.INGREDIENT_FILLING_1_PRICE + ) + return ingredient + +@pytest.fixture +def sauce(): + ingredient = Ingredient( + D.INGREDIENT_TYPE_SAUCE, + D.INGREDIENT_SAUCE_NAME, + D.INGREDIENT_SAUCE_PRICE + ) + return ingredient + +@pytest.fixture +def burger(): + return Burger() + diff --git a/data.py b/data.py new file mode 100644 index 000000000..949182cf8 --- /dev/null +++ b/data.py @@ -0,0 +1,26 @@ +BUN_PARAMS = [ + ('Black bun', 100), + ('White bun', 80.5), + ('',0), + ('Test', -20) +] + +INGREDIENT_PARAMS = [ + ("SAUCE", "Hot sauce", 50), + ("FILLING", "Cutlet", 100), + ("SAUCE", "Sour cream", 200), + ("", "Empty type", 0), + ("FILLING", "", 50), +] + +BURGER_BUN_NAME = 'Black Bun' +BURGER_BUN_PRICE = 100 +INGREDIENT_TYPE_SAUCE = 'SAUCE' +INGREDIENT_TYPE_FILLING = 'FILLING' +INGREDIENT_FILLING_NAME = 'Cutlet' +INGREDIENT_SAUCE_NAME = 'Hot sauce' +INGREDIENT_FILLING_1_PRICE = 50 +INGREDIENT_FILLING_2_PRICE = 30 +INGREDIENT_SAUCE_PRICE = 25 +BURGER_EXPECTED_TOTAL = 280 +EXPECTED_RECEIPT = '(==== Black Bun ====)\n= filling Cutlet =\n(==== Black Bun ====)\n\nPrice: 250' \ No newline at end of file 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 000000000..cffeec658 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +pytest +pytest-cov \ No newline at end of file diff --git a/tests/test_bun.py b/tests/test_bun.py index 09d5ed0a9..7a02b7341 100644 --- a/tests/test_bun.py +++ b/tests/test_bun.py @@ -1,17 +1,19 @@ import pytest +import data as D from praktikum.bun import Bun -from data import BUN_PARAMS + + class TestBun: - @pytest.mark.parametrize('name, price', BUN_PARAMS) + @pytest.mark.parametrize('name, price', D.BUN_PARAMS) def test_bun_creation(self, name, price): bun = Bun(name, price) assert bun.name == name assert bun.price == price def test_get_name(self, bun): - assert bun.get_name() == 'Test Bun' + assert bun.get_name() == D.BURGER_BUN_NAME def test_get_price(self, bun): - assert bun.get_price() == 100 \ No newline at end of file + assert bun.get_price() == D.BURGER_BUN_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..af8a2456e --- /dev/null +++ b/tests/test_burger.py @@ -0,0 +1,61 @@ +import pytest +import data as D +from unittest.mock import Mock + + +class TestBurger: + + def test_set_buns(self, burger): + mock_bun = Mock() + mock_bun.get_price.return_value = D.BURGER_BUN_PRICE + burger.set_buns(mock_bun) + assert burger.bun is mock_bun + + def test_add_ingredient(self, burger): + mock_ingredient = Mock() + mock_ingredient.get_price.return_value = D.INGREDIENT_FILLING_1_PRICE + burger.add_ingredient(mock_ingredient) + assert mock_ingredient in burger.ingredients + + def test_get_price(self, burger): + mock_bun = Mock() + mock_bun.get_price.return_value = D.BURGER_BUN_PRICE + mock_ingr1 = Mock() + mock_ingr2 = Mock() + mock_ingr1.get_price.return_value = D.INGREDIENT_FILLING_1_PRICE + mock_ingr2.get_price.return_value = D.INGREDIENT_FILLING_2_PRICE + burger.set_buns(mock_bun) + burger.add_ingredient(mock_ingr1) + burger.add_ingredient(mock_ingr2) + assert burger.get_price() == D.BURGER_EXPECTED_TOTAL + + def test_remove_ingredient(self, burger): + mock_ingr1 = Mock() + mock_ingr2 = Mock() + mock_ingr1.get_price.return_value = D.INGREDIENT_FILLING_1_PRICE + mock_ingr2.get_price.return_value = D.INGREDIENT_FILLING_2_PRICE + burger.add_ingredient(mock_ingr1) + burger.add_ingredient(mock_ingr2) + burger.remove_ingredient(0) + assert len(burger.ingredients) == 1 + assert mock_ingr1 not in burger.ingredients + + def test_move_ingredient(self, burger): + mock_first = Mock() + mock_second = Mock() + burger.add_ingredient(mock_first) + burger.add_ingredient(mock_second) + burger.move_ingredient(0, 1) + assert burger.ingredients == [mock_second, mock_first] + + def test_get_receipt(self, burger): + mock_bun = Mock() + mock_ingr = Mock() + mock_bun.get_name.return_value = D.BURGER_BUN_NAME + mock_bun.get_price.return_value = D.BURGER_BUN_PRICE + burger.set_buns(mock_bun) + mock_ingr.get_type.return_value = D.INGREDIENT_TYPE_FILLING + mock_ingr.get_name.return_value = D.INGREDIENT_FILLING_NAME + mock_ingr.get_price.return_value = D.INGREDIENT_FILLING_1_PRICE + burger.add_ingredient(mock_ingr) + assert burger.get_receipt() == D.EXPECTED_RECEIPT diff --git a/tests/test_ingredient.py b/tests/test_ingredient.py new file mode 100644 index 000000000..99925d16f --- /dev/null +++ b/tests/test_ingredient.py @@ -0,0 +1,22 @@ +import pytest +import data as D +from praktikum.ingredient import Ingredient + + +class TestIngredient: + + @pytest.mark.parametrize('ingredient_type, name, price', D.INGREDIENT_PARAMS) + def test_creation(self, ingredient_type, name, price): + ingredient = Ingredient(ingredient_type, name, price) + assert ingredient.type == ingredient_type + assert ingredient.name == name + assert ingredient.price == price + + def test_get_ingredient_type(self, filling): + assert filling.get_type() == D.INGREDIENT_TYPE_FILLING + + def test_get_ingredient_name(self, filling): + assert filling.get_name() == D.INGREDIENT_FILLING_NAME + + def test_get_ingredient_price(self, filling): + assert filling.get_price() == D.INGREDIENT_FILLING_1_PRICE \ No newline at end of file From fc41cd0ff950c9c912c62eac13e6690e64561b37 Mon Sep 17 00:00:00 2001 From: Dmitriy Date: Fri, 15 May 2026 20:38:57 +0300 Subject: [PATCH 3/5] =?UTF-8?q?test:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D1=82=D1=8C=20=D1=82=D0=B5=D1=81=D1=82=D1=8B=20=D0=B4?= =?UTF-8?q?=D0=BB=D1=8F=20Database?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_database.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 tests/test_database.py diff --git a/tests/test_database.py b/tests/test_database.py new file mode 100644 index 000000000..552858a6f --- /dev/null +++ b/tests/test_database.py @@ -0,0 +1,17 @@ +import pytest +from praktikum.database import Database +from praktikum.ingredient import Ingredient + + +class TestDatabase: + def test_available_buns(self): + db = Database() + buns = db.available_buns() + assert len(buns) == 3 + assert isinstance(buns, list) + + def test_available_ingredients(self): + db = Database() + ingredients = db.available_ingredients() + assert len(ingredients) == 6 + assert isinstance(ingredients, list) \ No newline at end of file From 9ac93f19eeae3818f2df265852175543f0158d9f Mon Sep 17 00:00:00 2001 From: Dmitriy Date: Fri, 15 May 2026 20:43:11 +0300 Subject: [PATCH 4/5] =?UTF-8?q?chore:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D1=82=D1=8C=20requirements.txt=20=D1=81=20=D0=B7=D0=B0?= =?UTF-8?q?=D0=B2=D0=B8=D1=81=D0=B8=D0=BC=D0=BE=D1=81=D1=82=D1=8F=D0=BC?= =?UTF-8?q?=D0=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- requirements.txt | Bin 17 -> 276 bytes 1 file changed, 0 insertions(+), 0 deletions(-) diff --git a/requirements.txt b/requirements.txt index cffeec658252c4285de76fc69815697f4517bc62..a3673a7927921583f8269769621239456ce737ba 100644 GIT binary patch literal 276 zcmYL^Q3}E^5Jcx&@F+?frQ(No@Cs65C~6E^3%$JhvNe^kN!WS2JNtRJy6Z|jbkdDD za4M~}B^oWYP$mX>BLZ(GcBr*6l`);7IwPab{DM&qYC}v+qI;_gcYug9(?B@ul5p}O wA2eEhjgr-={zx|9(No*&IZtrrx6ByPJZf+H-m0^Uyh)-%QCGjc{@au}U&w_i2LJ#7 literal 17 UcmXS@EJ-ac;VJ-Ay2<%v06s$o(f|Me From 7bc2fd569b5e76c23eb11ec9508bdc642102ed07 Mon Sep 17 00:00:00 2001 From: Dmitriy Date: Fri, 15 May 2026 20:50:38 +0300 Subject: [PATCH 5/5] =?UTF-8?q?chore:=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2?= =?UTF-8?q?=D0=B8=D1=82=D1=8C=20=D0=BE=D1=82=D1=87=D1=91=D1=82=20=D0=BF?= =?UTF-8?q?=D0=BE=D0=BA=D1=80=D1=8B=D1=82=D0=B8=D1=8F=20pytest-cov?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- coverage_report.txt | Bin 0 -> 2748 bytes 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 coverage_report.txt diff --git a/coverage_report.txt b/coverage_report.txt new file mode 100644 index 0000000000000000000000000000000000000000..4b05ac8716c61b4356d24bb529e68cf5408753be GIT binary patch literal 2748 zcmc(hOK;Oq5QWbgiT~gYJB;#xK#{sYMXY#9L~I&lrHv_}Nov_?QT{yeo$I=GXlg}i zOErpfpL5R49UtF6zxTDPMOrFV!879NR-viRv$y1=&h2RujmN>m5TOo)1`U|(zEfH`-V=Qa8Om63 zLC^e08WLNfQ~KSjXwAnF76J1(tdI2)Ugp;c>pVKcN~9Dn5&oPJH0rB5+k zV|l+BjAVubs;Hfz>*$31xk9Eq7gWHeT>A9yn(-m^+QBM@uEpK8z&mTrv96SFhO1*7 zs^m6GQ}Qyyq}8sYS{K?hs#c&)`V^yUJ|pW#Os=9<^yKQD{>Y9w=eg^deW4EK{G3PI z2Uu9a-L|$};5!e!dakS`=g6x2FlO{DocJm1rzqz+ag0LN%+KoQ6Rc{yEkDk7ZB?(T z*_)8ob+g{z)_T>ziNYy+^)^WV>R%g5sj1Bs+s1U0jx~L)w|lT}j%nYOrih) literal 0 HcmV?d00001