-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Выполнено задание 1. Написаны юнит-тесты с моками и параметризацией #717
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
Rimmarndkva
wants to merge
3
commits into
Yandex-Practicum:main
Choose a base branch
from
Rimmarndkva: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
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
Binary file not shown.
Binary file not shown.
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,3 @@ | ||
| __pycache__/ | ||
| .vscode/ | ||
| vscode/ |
File renamed without changes.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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.
Empty file.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,30 @@ | ||
| import pytest | ||
| from praktikum.bun import Bun | ||
|
|
||
| class TestBun: | ||
|
|
||
| def test_bun_initialization_sets_name_correctly(self): | ||
| bun = Bun("black bun", 100) | ||
| assert bun.name == "black bun" | ||
|
|
||
| def test_bun_initialization_sets_price_correctly(self): | ||
| bun = Bun("black bun", 100) | ||
| assert bun.price == 100 | ||
|
|
||
| def test_get_name_returns_correct_name(self): | ||
| bun = Bun("white bun", 200) | ||
| assert bun.get_name() == "white bun" | ||
|
|
||
| def test_get_price_returns_correct_price(self): | ||
| bun = Bun("red bun", 300) | ||
| assert bun.get_price() == 300 | ||
|
|
||
| @pytest.mark.parametrize("name, price", [ | ||
| ("very long name of a bun", 99.99), | ||
| ("", 0), | ||
| ("bun with special symbols %$#", -50) | ||
| ]) | ||
| def test_bun_creation_with_various_parameters(self, name, price): | ||
| bun = Bun(name, price) | ||
| assert bun.get_name() == name | ||
| 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,88 @@ | ||
| import pytest | ||
| from unittest.mock import Mock | ||
| from praktikum.burger import Burger | ||
|
|
||
|
|
||
| class TestBurger: | ||
|
|
||
| def test_set_buns_success(self): | ||
| burger = Burger() | ||
| mock_bun = Mock() | ||
|
|
||
| burger.set_buns(mock_bun) | ||
|
|
||
| assert burger.bun == mock_bun | ||
|
|
||
| def test_add_ingredient_success(self): | ||
| burger = Burger() | ||
| mock_ingredient = Mock() | ||
|
|
||
| burger.add_ingredient(mock_ingredient) | ||
|
|
||
| assert mock_ingredient in burger.ingredients | ||
| assert len(burger.ingredients) == 1 | ||
|
|
||
| def test_remove_ingredient_success(self): | ||
| burger = Burger() | ||
| mock_ingredient = Mock() | ||
| burger.ingredients.append(mock_ingredient) | ||
|
|
||
| burger.remove_ingredient(0) | ||
|
|
||
| assert len(burger.ingredients) == 0 | ||
|
|
||
| def test_move_ingredient_success(self): | ||
| burger = Burger() | ||
| mock_ingredient_1 = Mock() | ||
| mock_ingredient_2 = Mock() | ||
| burger.ingredients.extend([mock_ingredient_1, mock_ingredient_2]) | ||
|
|
||
| burger.move_ingredient(0, 1) | ||
|
|
||
| assert burger.ingredients[0] == mock_ingredient_2 | ||
| assert burger.ingredients[1] == mock_ingredient_1 | ||
|
|
||
| @pytest.mark.parametrize("bun_price, ing_price, expected", [ | ||
| (100, 50, 250), | ||
| (200, 100, 500), | ||
| (0, 0, 0) | ||
| ]) | ||
| def test_get_price_calculates_correctly(self, bun_price, ing_price, expected): | ||
| burger = Burger() | ||
|
|
||
| mock_bun = Mock() | ||
| mock_bun.get_price.return_value = bun_price | ||
| burger.set_buns(mock_bun) | ||
|
|
||
| mock_ingredient = Mock() | ||
| mock_ingredient.get_price.return_value = ing_price | ||
| burger.add_ingredient(mock_ingredient) | ||
|
|
||
| assert burger.get_price() == expected | ||
|
|
||
| def test_get_receipt_returns_correct_string(self): | ||
| burger = Burger() | ||
|
|
||
| mock_bun = Mock() | ||
| mock_bun.get_name.return_value = "black bun" | ||
| mock_bun.get_price.return_value = 100 | ||
| burger.set_buns(mock_bun) | ||
|
|
||
|
|
||
| mock_ingredient = Mock() | ||
| mock_ingredient.get_type.return_value = "SAUCE" | ||
| mock_ingredient.get_name.return_value = "hot sauce" | ||
| mock_ingredient.get_price.return_value = 100 | ||
| burger.add_ingredient(mock_ingredient) | ||
|
|
||
| receipt = burger.get_receipt() | ||
|
|
||
| expected_receipt = ( | ||
| "(==== black bun ====)\n" | ||
| "= sauce hot sauce =\n" | ||
| "(==== black bun ====)\n" | ||
| "\n" | ||
| "Price: 300" | ||
| ) | ||
|
|
||
| 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,19 @@ | ||
| import pytest | ||
| from praktikum.database import Database | ||
|
|
||
| class TestDatabase: | ||
|
|
||
| def test_available_buns_returns_not_empty_list(self): | ||
| database = Database() | ||
| buns = database.available_buns() | ||
|
|
||
| assert len(buns) == 3 | ||
|
|
||
| assert buns[0].get_name() == "black bun" | ||
|
|
||
| def test_available_ingredients_returns_not_empty_list(self): | ||
| database = Database() | ||
| ingredients = database.available_ingredients() | ||
|
|
||
| assert len(ingredients) == 6 | ||
| assert ingredients[0].get_name() == "hot sauce" |
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,23 @@ | ||
| import pytest | ||
| from praktikum.ingredient import Ingredient | ||
|
|
||
| class TestIngredient: | ||
|
|
||
| def test_ingredient_initialization(self): | ||
| ingredient = Ingredient("SAUCE", "hot sauce", 100.0) | ||
|
|
||
| assert ingredient.type == "SAUCE" | ||
| assert ingredient.name == "hot sauce" | ||
| assert ingredient.price == 100.0 | ||
|
|
||
| def test_get_price_returns_correct_price(self): | ||
| ingredient = Ingredient("FILLING", "cutlet", 150.0) | ||
| assert ingredient.get_price() == 150.0 | ||
|
|
||
| def test_get_name_returns_correct_name(self): | ||
| ingredient = Ingredient("SAUCE", "sour cream", 50.0) | ||
| assert ingredient.get_name() == "sour cream" | ||
|
|
||
| def test_get_type_returns_correct_type(self): | ||
| ingredient = Ingredient("FILLING", "sausage", 200.0) | ||
| assert ingredient.get_type() == "FILLING" |
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.
Необходимо исправить: эта директория лишняя в проекте. Необходимо убрать её из ветки и добавить в .gitignore в корне проекта