-
Notifications
You must be signed in to change notification settings - Fork 1.1k
add new changes #633
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
Modmoonka
wants to merge
1
commit into
Yandex-Practicum:main
Choose a base branch
from
Modmoonka: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
add new changes #633
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
Binary file not shown.
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
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.
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
Binary file not shown.
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,10 @@ | ||
| import pytest | ||
| from praktikumm.bun import Bun | ||
|
|
||
| def test_bun_get_name(): | ||
| bun = Bun("white", 200) | ||
| assert bun.get_name() == "white" | ||
|
|
||
| def test_bun_get_price(): | ||
| bun = Bun("black", 100) | ||
| assert bun.get_price() == 100 |
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,52 @@ | ||
| import pytest | ||
| from unittest.mock import Mock | ||
| from praktikumm.burger import Burger | ||
| from praktikumm.bun import Bun | ||
| from praktikumm.ingredient import Ingredient | ||
|
|
||
| @pytest.fixture | ||
| def burger(): | ||
| return Burger() | ||
|
|
||
| def test_set_buns(burger): | ||
| bun = Bun("black bun", 100) | ||
| burger.set_buns(bun) | ||
| assert burger.bun == bun | ||
|
|
||
| @pytest.mark.parametrize("ingredient_type, name, price", [ | ||
| ("SAUCE", "hot sauce", 100), | ||
| ("FILLING", "sausage", 300) | ||
| ]) | ||
| def test_add_ingredient(burger, ingredient_type, name, price): | ||
| ingredient = Ingredient(ingredient_type, name, price) | ||
| burger.add_ingredient(ingredient) | ||
| assert len(burger.ingredients) == 1 | ||
| assert burger.ingredients[0] == ingredient | ||
|
|
||
| def test_remove_ingredient(burger): | ||
| ingredient = Ingredient("SAUCE", "sour cream", 150) | ||
| burger.add_ingredient(ingredient) | ||
| idx = 0 | ||
| burger.remove_ingredient(idx) | ||
| assert len(burger.ingredients) == 0 | ||
|
|
||
| def test_get_price_with_mock(burger): | ||
| bun = Mock() | ||
| bun.get_price.return_value = 60 | ||
| burger.set_buns(bun) | ||
|
|
||
| ingredient = Mock() | ||
| ingredient.get_price.return_value = 60 | ||
| burger.add_ingredient(ingredient) | ||
|
|
||
| expected = 60 * 2 + 60 # <-- исправлено | ||
| assert burger.get_price() == expected | ||
|
|
||
| def test_get_receipt(burger): | ||
| bun = Bun("white bun", 200) | ||
| burger.set_buns(bun) | ||
| ingredient = Ingredient("SAUCE", "chili sauce", 300) | ||
| burger.add_ingredient(ingredient) | ||
|
|
||
| expected = "(==== white bun ====)\n= sauce chili sauce =\n(==== white bun ====)\nPrice: 700" | ||
| assert burger.get_receipt() == expected | ||
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,29 @@ | ||
| import pytest | ||
| from praktikumm.database import Database | ||
| from praktikumm.bun import Bun | ||
| from praktikumm.ingredient import Ingredient | ||
|
|
||
| def test_available_buns(): | ||
| db = Database() | ||
| buns = db.available_buns() | ||
| assert len(buns) == 3 | ||
| assert isinstance(buns[0], Bun) | ||
|
|
||
| def test_available_ingredients(): | ||
| db = Database() | ||
| ingredients = db.available_ingredients() | ||
| assert len(ingredients) == 6 | ||
| assert isinstance(ingredients[0], Ingredient) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Можно лучше: мы тестируем не атрибуты экземпляров класса или наполнение базы данных, а методы приложения. Необходимо добавить шаги в которых будут использованы методы и проверить результат. Базу данных тестировать юниттестами не получится |
||
|
|
||
| def test_buns_have_correct_data(): | ||
| db = Database() | ||
| bun = db.available_buns()[0] | ||
| assert bun.get_name() == "black bun" | ||
| assert bun.get_price() == 100 | ||
|
|
||
| def test_ingredients_have_correct_data(): | ||
| db = Database() | ||
| ingredient = db.available_ingredients()[0] | ||
| assert ingredient.get_type() == "SAUCE" | ||
| assert ingredient.get_name() == "hot sauce" | ||
| assert ingredient.get_price() == 100 | ||
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,14 @@ | ||
| import pytest | ||
| from praktikumm.ingredient import Ingredient | ||
|
|
||
| def test_ingredient_get_name(): | ||
| ingredient = Ingredient("SAUCE", "hot sauce", 100) | ||
| assert ingredient.get_name() == "hot sauce" | ||
|
|
||
| def test_ingredient_get_price(): | ||
| ingredient = Ingredient("FILLING", "sausage", 300) | ||
| assert ingredient.get_price() == 300 | ||
|
|
||
| def test_ingredient_get_type(): | ||
| ingredient = Ingredient("SAUCE", "sour cream", 150) | ||
| assert ingredient.get_type() == "SAUCE" |
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.
Отлично: благодаря мокам тесты стали быстрее и управляемее, теперь они меньше зависят от внешних данных