-
Notifications
You must be signed in to change notification settings - Fork 1.5k
done #905
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Interlude312
wants to merge
1
commit into
Yandex-Practicum:main
Choose a base branch
from
Interlude312:develop1
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
done #905
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| __pycache__/ | ||
| *.pyc | ||
| .pytest_cache/ | ||
| .coverage | ||
| htmlcov/ | ||
| *.egg-info/ | ||
| .venv/ | ||
| venv/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| [pytest] | ||
| testpaths = tests |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| pytest==8.3.4 | ||
| pytest-cov==7.1.0 |
Empty file.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| from unittest.mock import Mock | ||
|
|
||
| import pytest | ||
|
|
||
| from praktikum.bun import Bun | ||
| from praktikum.burger import Burger | ||
| from praktikum.database import Database | ||
| from praktikum.ingredient import Ingredient | ||
| from tests.data import BURGER_BUN, BURGER_INGREDIENTS | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def burger(): | ||
| return Burger() | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def bun_mock(): | ||
| bun = Mock(spec=Bun) | ||
| bun.get_name.return_value = BURGER_BUN[0] | ||
| bun.get_price.return_value = BURGER_BUN[1] | ||
| return bun | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def ingredient_mocks(): | ||
| mocks = [] | ||
| for ingredient_type, name, price in BURGER_INGREDIENTS: | ||
| ingredient = Mock(spec=Ingredient) | ||
| ingredient.get_type.return_value = ingredient_type | ||
| ingredient.get_name.return_value = name | ||
| ingredient.get_price.return_value = price | ||
| mocks.append(ingredient) | ||
| return mocks | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def database(): | ||
| return Database() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| from praktikum.ingredient_types import INGREDIENT_TYPE_FILLING, INGREDIENT_TYPE_SAUCE | ||
|
|
||
| BUN_CASES = ( | ||
| ("classic bun", 100), | ||
| ("premium bun", 200.5), | ||
| ) | ||
|
|
||
| INGREDIENT_CASES = ( | ||
| (INGREDIENT_TYPE_SAUCE, "spicy sauce", 50), | ||
| (INGREDIENT_TYPE_FILLING, "beef patty", 150), | ||
| ) | ||
|
|
||
| BURGER_BUN = ("test bun", 100) | ||
|
|
||
| BURGER_INGREDIENTS = ( | ||
| (INGREDIENT_TYPE_SAUCE, "hot sauce", 30), | ||
| (INGREDIENT_TYPE_FILLING, "cutlet", 120), | ||
| (INGREDIENT_TYPE_SAUCE, "mayo", 25), | ||
| ) | ||
|
|
||
| REMOVE_INGREDIENT_CASES = ( | ||
| (0, (1, 2)), | ||
| (1, (0, 2)), | ||
| (2, (0, 1)), | ||
| (-1, (0, 1)), | ||
| ) | ||
|
|
||
| MOVE_INGREDIENT_CASES = ( | ||
| (0, 2, (1, 2, 0)), | ||
| (2, 0, (2, 0, 1)), | ||
| (1, 1, (0, 1, 2)), | ||
| ) | ||
|
|
||
| DATABASE_BUN_NAMES = ("black bun", "white bun", "red bun") | ||
| DATABASE_BUN_PRICES = (100, 200, 300) | ||
| DATABASE_INGREDIENT_COUNT = 6 | ||
| DATABASE_SAUCE_COUNT = 3 | ||
| DATABASE_FILLING_COUNT = 3 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import pytest | ||
|
|
||
| from praktikum.bun import Bun | ||
| from tests.data import BUN_CASES | ||
|
|
||
|
|
||
| class TestBun: | ||
| @pytest.mark.parametrize("name, price", BUN_CASES) | ||
| def test_get_name_returns_given_name(self, name, price): | ||
| bun = Bun(name, price) | ||
|
|
||
| assert bun.get_name() == name | ||
|
|
||
| @pytest.mark.parametrize("name, price", BUN_CASES) | ||
| def test_get_price_returns_given_price(self, name, price): | ||
| bun = Bun(name, price) | ||
|
|
||
| assert bun.get_price() == price |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,92 @@ | ||
| import pytest | ||
|
|
||
| from tests.data import ( | ||
| BURGER_BUN, | ||
| BURGER_INGREDIENTS, | ||
| MOVE_INGREDIENT_CASES, | ||
| REMOVE_INGREDIENT_CASES, | ||
| ) | ||
|
|
||
|
|
||
| class TestBurger: | ||
| def test_get_price_without_ingredients_returns_double_bun_price(self, burger, bun_mock): | ||
| burger.set_buns(bun_mock) | ||
|
|
||
| assert burger.get_price() == BURGER_BUN[1] * 2 | ||
| bun_mock.get_price.assert_called_once_with() | ||
|
|
||
| def test_add_ingredient_includes_ingredient_in_price(self, burger, bun_mock, ingredient_mocks): | ||
| burger.set_buns(bun_mock) | ||
| burger.add_ingredient(ingredient_mocks[0]) | ||
|
|
||
| expected_price = BURGER_BUN[1] * 2 + BURGER_INGREDIENTS[0][2] | ||
| assert burger.get_price() == expected_price | ||
| assert burger.ingredients == [ingredient_mocks[0]] | ||
|
|
||
| def test_get_price_with_several_ingredients_returns_total(self, burger, bun_mock, ingredient_mocks): | ||
| burger.set_buns(bun_mock) | ||
| for ingredient in ingredient_mocks: | ||
| burger.add_ingredient(ingredient) | ||
|
|
||
| expected_price = BURGER_BUN[1] * 2 + sum(item[2] for item in BURGER_INGREDIENTS) | ||
| assert burger.get_price() == expected_price | ||
|
|
||
| @pytest.mark.parametrize("index, remaining_indices", REMOVE_INGREDIENT_CASES) | ||
| def test_remove_ingredient_excludes_item_from_price( | ||
| self, burger, bun_mock, ingredient_mocks, index, remaining_indices | ||
| ): | ||
| burger.set_buns(bun_mock) | ||
| for ingredient in ingredient_mocks: | ||
| burger.add_ingredient(ingredient) | ||
|
|
||
| burger.remove_ingredient(index) | ||
|
|
||
| expected_price = BURGER_BUN[1] * 2 + sum( | ||
| BURGER_INGREDIENTS[item_index][2] for item_index in remaining_indices | ||
| ) | ||
| assert burger.get_price() == expected_price | ||
| assert burger.ingredients == [ingredient_mocks[item_index] for item_index in remaining_indices] | ||
|
|
||
| @pytest.mark.parametrize("index, new_index, expected_order", MOVE_INGREDIENT_CASES) | ||
| def test_move_ingredient_changes_order( | ||
| self, burger, bun_mock, ingredient_mocks, index, new_index, expected_order | ||
| ): | ||
| burger.set_buns(bun_mock) | ||
| for ingredient in ingredient_mocks: | ||
| burger.add_ingredient(ingredient) | ||
|
|
||
| burger.move_ingredient(index, new_index) | ||
|
|
||
| assert burger.ingredients == [ingredient_mocks[item_index] for item_index in expected_order] | ||
|
|
||
| def test_get_receipt_without_ingredients_returns_bun_only(self, burger, bun_mock): | ||
| burger.set_buns(bun_mock) | ||
|
|
||
| receipt = burger.get_receipt() | ||
|
|
||
| expected_receipt = "\n".join( | ||
| [ | ||
| f"(==== {BURGER_BUN[0]} ====)", | ||
| f"(==== {BURGER_BUN[0]} ====)\n", | ||
| f"Price: {burger.get_price()}", | ||
| ] | ||
| ) | ||
| assert receipt == expected_receipt | ||
|
|
||
| def test_get_receipt_returns_formatted_receipt(self, burger, bun_mock, ingredient_mocks): | ||
| burger.set_buns(bun_mock) | ||
| for ingredient in ingredient_mocks[:2]: | ||
| burger.add_ingredient(ingredient) | ||
|
|
||
| receipt = burger.get_receipt() | ||
|
|
||
| expected_receipt = "\n".join( | ||
| [ | ||
| f"(==== {BURGER_BUN[0]} ====)", | ||
| f"= {BURGER_INGREDIENTS[0][0].lower()} {BURGER_INGREDIENTS[0][1]} =", | ||
| f"= {BURGER_INGREDIENTS[1][0].lower()} {BURGER_INGREDIENTS[1][1]} =", | ||
| f"(==== {BURGER_BUN[0]} ====)\n", | ||
| f"Price: {burger.get_price()}", | ||
| ] | ||
| ) | ||
| assert receipt == expected_receipt |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| from praktikum.ingredient_types import INGREDIENT_TYPE_FILLING, INGREDIENT_TYPE_SAUCE | ||
| from tests.data import ( | ||
| DATABASE_BUN_NAMES, | ||
| DATABASE_BUN_PRICES, | ||
| DATABASE_FILLING_COUNT, | ||
| DATABASE_INGREDIENT_COUNT, | ||
| DATABASE_SAUCE_COUNT, | ||
| ) | ||
|
|
||
|
|
||
| class TestDatabase: | ||
| def test_available_buns_returns_all_buns(self, database): | ||
| buns = database.available_buns() | ||
|
|
||
| assert len(buns) == len(DATABASE_BUN_NAMES) | ||
| assert tuple(bun.get_name() for bun in buns) == DATABASE_BUN_NAMES | ||
| assert tuple(bun.get_price() for bun in buns) == DATABASE_BUN_PRICES | ||
|
|
||
| def test_available_ingredients_returns_sauces_and_fillings(self, database): | ||
| ingredients = database.available_ingredients() | ||
| types = [ingredient.get_type() for ingredient in ingredients] | ||
|
|
||
| assert len(ingredients) == DATABASE_INGREDIENT_COUNT | ||
| assert types.count(INGREDIENT_TYPE_SAUCE) == DATABASE_SAUCE_COUNT | ||
| assert types.count(INGREDIENT_TYPE_FILLING) == DATABASE_FILLING_COUNT |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| import pytest | ||
|
|
||
| from praktikum.ingredient import Ingredient | ||
| from tests.data import INGREDIENT_CASES | ||
|
|
||
|
|
||
| class TestIngredient: | ||
| @pytest.mark.parametrize("ingredient_type, name, price", INGREDIENT_CASES) | ||
| def test_get_type_returns_given_type(self, ingredient_type, name, price): | ||
| ingredient = Ingredient(ingredient_type, name, price) | ||
|
|
||
| assert ingredient.get_type() == ingredient_type | ||
|
|
||
| @pytest.mark.parametrize("ingredient_type, name, price", INGREDIENT_CASES) | ||
| def test_get_name_returns_given_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_CASES) | ||
| def test_get_price_returns_given_price(self, ingredient_type, name, price): | ||
| ingredient = Ingredient(ingredient_type, name, price) | ||
|
|
||
| assert ingredient.get_price() == price |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Нужно исправить: в директории tests хранятся только тесты и conftest, все остальное должно быть в корне