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
12 changes: 12 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Виртуальное окружение
venv/
.venv/

# Кеш Python
__pycache__/
.pytest_cache/
*.pyc

# Отчёты покрытия
.coverage
htmlcov/
34 changes: 34 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import pytest
import data as D
from praktikum.bun import Bun
from praktikum.burger import Burger
from praktikum.ingredient import Ingredient


@pytest.fixture
def bun():
bun = Bun(D.BURGER_BUN_NAME, D.BURGER_BUN_PRICE)
return bun

@pytest.fixture
def filling():
ingredient = Ingredient(
D.INGREDIENT_TYPE_FILLING,
D.INGREDIENT_FILLING_NAME,
D.INGREDIENT_FILLING_1_PRICE
)
return ingredient

@pytest.fixture
def sauce():
ingredient = Ingredient(
D.INGREDIENT_TYPE_SAUCE,
D.INGREDIENT_SAUCE_NAME,
D.INGREDIENT_SAUCE_PRICE
)
return ingredient

@pytest.fixture
def burger():
return Burger()

Binary file added coverage_report.txt
Binary file not shown.
26 changes: 26 additions & 0 deletions data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
BUN_PARAMS = [
('Black bun', 100),
('White bun', 80.5),
('',0),
('Test', -20)
]

INGREDIENT_PARAMS = [
("SAUCE", "Hot sauce", 50),
("FILLING", "Cutlet", 100),
("SAUCE", "Sour cream", 200),
("", "Empty type", 0),
("FILLING", "", 50),
]

BURGER_BUN_NAME = 'Black Bun'
BURGER_BUN_PRICE = 100
INGREDIENT_TYPE_SAUCE = 'SAUCE'
INGREDIENT_TYPE_FILLING = 'FILLING'
INGREDIENT_FILLING_NAME = 'Cutlet'
INGREDIENT_SAUCE_NAME = 'Hot sauce'
INGREDIENT_FILLING_1_PRICE = 50
INGREDIENT_FILLING_2_PRICE = 30
INGREDIENT_SAUCE_PRICE = 25
BURGER_EXPECTED_TOTAL = 280
EXPECTED_RECEIPT = '(==== Black Bun ====)\n= filling Cutlet =\n(==== Black Bun ====)\n\nPrice: 250'
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Binary file added requirements.txt
Binary file not shown.
Empty file added tests/__init__.py
Empty file.
19 changes: 19 additions & 0 deletions tests/test_bun.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import pytest
import data as D
from praktikum.bun import Bun



class TestBun:

@pytest.mark.parametrize('name, price', D.BUN_PARAMS)
def test_bun_creation(self, name, price):
bun = Bun(name, price)
assert bun.name == name
assert bun.price == price

def test_get_name(self, bun):
assert bun.get_name() == D.BURGER_BUN_NAME

def test_get_price(self, bun):
assert bun.get_price() == D.BURGER_BUN_PRICE
61 changes: 61 additions & 0 deletions tests/test_burger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import pytest
import data as D
from unittest.mock import Mock


class TestBurger:

def test_set_buns(self, burger):
mock_bun = Mock()
mock_bun.get_price.return_value = D.BURGER_BUN_PRICE
burger.set_buns(mock_bun)
assert burger.bun is mock_bun

def test_add_ingredient(self, burger):
mock_ingredient = Mock()
mock_ingredient.get_price.return_value = D.INGREDIENT_FILLING_1_PRICE
burger.add_ingredient(mock_ingredient)
assert mock_ingredient in burger.ingredients

def test_get_price(self, burger):
mock_bun = Mock()
mock_bun.get_price.return_value = D.BURGER_BUN_PRICE
mock_ingr1 = Mock()
mock_ingr2 = Mock()
mock_ingr1.get_price.return_value = D.INGREDIENT_FILLING_1_PRICE
mock_ingr2.get_price.return_value = D.INGREDIENT_FILLING_2_PRICE
burger.set_buns(mock_bun)
burger.add_ingredient(mock_ingr1)
burger.add_ingredient(mock_ingr2)
assert burger.get_price() == D.BURGER_EXPECTED_TOTAL

def test_remove_ingredient(self, burger):
mock_ingr1 = Mock()
mock_ingr2 = Mock()
mock_ingr1.get_price.return_value = D.INGREDIENT_FILLING_1_PRICE
mock_ingr2.get_price.return_value = D.INGREDIENT_FILLING_2_PRICE
burger.add_ingredient(mock_ingr1)
burger.add_ingredient(mock_ingr2)
burger.remove_ingredient(0)
assert len(burger.ingredients) == 1
assert mock_ingr1 not in burger.ingredients

def test_move_ingredient(self, burger):
mock_first = Mock()
mock_second = Mock()
burger.add_ingredient(mock_first)
burger.add_ingredient(mock_second)
burger.move_ingredient(0, 1)
assert burger.ingredients == [mock_second, mock_first]

def test_get_receipt(self, burger):
mock_bun = Mock()
mock_ingr = Mock()
mock_bun.get_name.return_value = D.BURGER_BUN_NAME
mock_bun.get_price.return_value = D.BURGER_BUN_PRICE
burger.set_buns(mock_bun)
mock_ingr.get_type.return_value = D.INGREDIENT_TYPE_FILLING
mock_ingr.get_name.return_value = D.INGREDIENT_FILLING_NAME
mock_ingr.get_price.return_value = D.INGREDIENT_FILLING_1_PRICE
burger.add_ingredient(mock_ingr)
assert burger.get_receipt() == D.EXPECTED_RECEIPT
17 changes: 17 additions & 0 deletions tests/test_database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import pytest
from praktikum.database import Database
from praktikum.ingredient import Ingredient


class TestDatabase:
def test_available_buns(self):
db = Database()
buns = db.available_buns()
assert len(buns) == 3
assert isinstance(buns, list)

def test_available_ingredients(self):
db = Database()
ingredients = db.available_ingredients()
assert len(ingredients) == 6
assert isinstance(ingredients, list)
22 changes: 22 additions & 0 deletions tests/test_ingredient.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import pytest
import data as D
from praktikum.ingredient import Ingredient


class TestIngredient:

@pytest.mark.parametrize('ingredient_type, name, price', D.INGREDIENT_PARAMS)
def test_creation(self, ingredient_type, name, price):
ingredient = Ingredient(ingredient_type, name, price)
assert ingredient.type == ingredient_type
assert ingredient.name == name
assert ingredient.price == price

def test_get_ingredient_type(self, filling):
assert filling.get_type() == D.INGREDIENT_TYPE_FILLING

def test_get_ingredient_name(self, filling):
assert filling.get_name() == D.INGREDIENT_FILLING_NAME

def test_get_ingredient_price(self, filling):
assert filling.get_price() == D.INGREDIENT_FILLING_1_PRICE