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 .DS_Store
Binary file not shown.
Binary file added .coverage
Binary file not shown.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"python-envs.pythonProjects": []
}
Binary file added __pycache__/praktikum.cpython-314.pyc
Binary file not shown.
File renamed without changes.
Binary file added praktikum/__pycache__/__init__.cpython-314.pyc
Binary file not shown.
Binary file added praktikum/__pycache__/bun.cpython-314.pyc
Binary file not shown.
Binary file added praktikum/__pycache__/burger.cpython-314.pyc
Binary file not shown.
Binary file added praktikum/__pycache__/database.cpython-314.pyc
Binary file not shown.
Binary file added praktikum/__pycache__/ingredient.cpython-314.pyc
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 added tests/__init__.py
Empty file.
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.
30 changes: 30 additions & 0 deletions tests/bun_test.py
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
83 changes: 83 additions & 0 deletions tests/burger_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
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()

assert "black bun" in receipt
assert "sauce" in receipt
assert "hot sauce" in receipt
assert "300" in receipt
19 changes: 19 additions & 0 deletions tests/database_test.py
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"
23 changes: 23 additions & 0 deletions tests/ingredient_test.py
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"