Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added .coverage
Binary file not shown.
7 changes: 7 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true
}
Binary file added __pycache__/__init__.cpython-314.pyc
Binary file not shown.
Binary file added __pycache__/bun.cpython-314.pyc
Binary file not shown.
Binary file added __pycache__/burger.cpython-314.pyc
Binary file not shown.
Binary file added __pycache__/database.cpython-314.pyc
Binary file not shown.
Binary file added __pycache__/ingredient.cpython-314.pyc
Binary file not shown.
Binary file added __pycache__/ingredient_types.cpython-314.pyc
Binary file not shown.
Binary file added __pycache__/praktikum.cpython-314.pyc
Binary file not shown.
Binary file added __pycache__/test_bun.cpython-314-pytest-9.0.1.pyc
Binary file not shown.
4 changes: 2 additions & 2 deletions burger.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
6 changes: 3 additions & 3 deletions database.py
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pytest
pytest-cov
Binary file added tests/__pycache__/__init__.cpython-314.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
18 changes: 18 additions & 0 deletions tests/test_bun.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
from bun import Bun

class TestBun:
def test_set_name_and_price(self):
bun = Bun('Bun', 100)

assert bun.name == 'Bun'
assert bun.price == 100

def test_get_name(self):
bun = Bun('Bun', 100)

assert bun.get_name() == 'Bun'

def test_get_price(self):
bun = Bun('Bun', 300)

assert bun.get_price() == 300
71 changes: 71 additions & 0 deletions tests/test_burger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
from burger import Burger
from unittest.mock import Mock

class TestBurger:
def test_set_buns(self):
burger = Burger()
mock_bun = Mock()
burger.set_buns(mock_bun)

assert burger.bun == mock_bun

def test_add_ingredient(self):
burger = Burger()
mock_ingredient = Mock()
burger.add_ingredient(mock_ingredient)

assert len(burger.ingredients) == 1
assert burger.ingredients[0] == mock_ingredient

def test_remove_ingredient(self):
burger = Burger()
mock_ingredient = Mock()
burger.add_ingredient(mock_ingredient)
burger.remove_ingredient(0)

assert len(burger.ingredients) == 0

def test_move_ingredient(self):
burger = Burger()
ingred_1 = Mock()
ingred_2 = Mock()
burger.add_ingredient(ingred_1)
burger.add_ingredient(ingred_2)

burger.move_ingredient(0, 1)

assert burger.ingredients[0] == ingred_2
assert burger.ingredients[1] == ingred_1

def test_get_price(self):
burger = Burger()

mock_bun = Mock()
mock_bun.get_price.return_value = 100
burger.set_buns(mock_bun)

mock_ingredient = Mock()
mock_ingredient.get_price.return_value = 50
burger.add_ingredient(mock_ingredient)

assert burger.get_price() == 250

def test_get_receipt(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_name.return_value = "Cutlet"
mock_ingredient.get_price.return_value = 50
mock_ingredient.get_type.return_value = "FILLING"
burger.add_ingredient(mock_ingredient)

receipt = burger.get_receipt()

assert "Black Bun" in receipt
assert "Cutlet" in receipt
assert "Price: 250" in receipt
29 changes: 29 additions & 0 deletions tests/test_database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
from database import Database

class TestDatabase:

def test_available_buns_returns_correct_count(self):
db = Database()
buns = db.available_buns()

assert len(buns) == 3

def test_available_ingredients_returns_correct_count(self):
db = Database()
ingredients = db.available_ingredients()

assert len(ingredients) == 6

def test_database_has_specific_bun(self):
db = Database()
buns = db.available_buns()

names = [bun.get_name() for bun in buns]
assert "white bun" in names

def test_database_has_specific_ingredient(self):
db = Database()
ingredients = db.available_ingredients()

names = [ing.get_name() for ing in ingredients]
assert "hot sauce" in names
31 changes: 31 additions & 0 deletions tests/test_ingredient.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import pytest
from ingredient import Ingredient
from ingredient_types import INGREDIENT_TYPE_SAUCE, INGREDIENT_TYPE_FILLING

class TestIngredient:

@pytest.mark.parametrize(
"ing_type, name, price",
[
(INGREDIENT_TYPE_SAUCE, "sour cream", 100),
(INGREDIENT_TYPE_FILLING, "cutlet", 200),
(INGREDIENT_TYPE_SAUCE, "chili sauce", 50),
]
)
def test_ingredient_getters(self, ing_type, name, price):
ingredient = Ingredient(ing_type, name, price)

assert ingredient.get_type() == ing_type
assert ingredient.get_name() == name
assert ingredient.get_price() == price

def test_ingredient_initialization(self):
ing_type = INGREDIENT_TYPE_FILLING
name = "chicken"
price = 150

ingredient = Ingredient(ing_type, name, price)

assert ingredient.type == ing_type
assert ingredient.name == name
assert ingredient.price == price