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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.venv
.pytest_cache
61 changes: 61 additions & 0 deletions conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
from praktikum.database import Database
from unittest.mock import Mock
from data import Data1, Data2
import pytest


@pytest.fixture
def mock_bun():
mock_for_bun = Mock()
mock_for_bun.get_name.return_value = Data1.bun_name
mock_for_bun.get_price.return_value = Data1.bun_price
return mock_for_bun


@pytest.fixture
def mock_bun_2():
mock_for_bun_2 = Mock()
mock_for_bun_2.get_name.return_value = Data2.bun_name
mock_for_bun_2.get_price.return_value = Data2.bun_price
return mock_for_bun_2


@pytest.fixture
def mock_sauce():
mock_for_sauce = Mock()
mock_for_sauce.get_name.return_value = Data1.sauce_name
mock_for_sauce.get_price.return_value = Data1.sauce_price
mock_for_sauce.get_type.return_value = Data1.sauce_type
return mock_for_sauce


@pytest.fixture
def mock_sauce_2():
mock_for_sauce_2 = Mock()
mock_for_sauce_2.get_name.return_value = Data2.sauce_name
mock_for_sauce_2.get_price.return_value = Data2.sauce_price
mock_for_sauce_2.get_type.return_value = Data2.sauce_type
return mock_for_sauce_2


@pytest.fixture
def mock_filling():
mock_for_filling = Mock()
mock_for_filling.get_name.return_value = Data1.filling_name
mock_for_filling.get_price.return_value = Data1.filling_price
mock_for_filling.get_type.return_value = Data1.filling_type
return mock_for_filling


@pytest.fixture
def mock_filling_2():
mock_for_filling_2 = Mock()
mock_for_filling_2.get_name.return_value = Data2.filling_name
mock_for_filling_2.get_price.return_value = Data2.filling_price
mock_for_filling_2.get_type.return_value = Data2.filling_type
return mock_for_filling_2


@pytest.fixture
def db():
return Database()
49 changes: 49 additions & 0 deletions data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
from praktikum.ingredient_types import INGREDIENT_TYPE_SAUCE, INGREDIENT_TYPE_FILLING


class Data1:
bun_name = 'Флюоресцентная булка R2-D3'
bun_price = 988

sauce_type = INGREDIENT_TYPE_SAUCE
sauce_name = 'Соус традиционный галактический'
sauce_price = 15

filling_type = INGREDIENT_TYPE_FILLING
filling_name = 'Мясо бессмертных моллюсков Protostomia'
filling_price = 1350

burger_final_cost = bun_price * 2 + sauce_price + filling_price


class Data2:
bun_name = 'Краторная булка N-200i'
bun_price = 1255

sauce_type = INGREDIENT_TYPE_SAUCE
sauce_name = 'Соус с шипами Антарианского плоскоходца'
sauce_price = 88

filling_type = INGREDIENT_TYPE_FILLING
filling_name = 'Сыр с астероидной плесенью'
filling_price = 4142

burger_final_cost = bun_price * 2 + sauce_price + filling_price


class TestDataBase:
test_data_base_buns = [
[0, 'black bun', 100],
[1, 'white bun', 200],
[2, 'red bun', 300]
]

test_data_base_ingredients = [
[0, INGREDIENT_TYPE_SAUCE, 'hot sauce', 100],
[1, INGREDIENT_TYPE_SAUCE, 'sour cream', 200],
[2, INGREDIENT_TYPE_SAUCE, 'chili sauce', 300],
[3, INGREDIENT_TYPE_FILLING, 'cutlet', 100],
[4, INGREDIENT_TYPE_FILLING, 'dinosaur', 200],
[5, INGREDIENT_TYPE_FILLING, 'sausage', 300]

]
File renamed without changes.
Binary file added praktikum/__pycache__/__init__.cpython-314.pyc
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Необходимо исправить: эта директория лишняя в проекте. Необходимо убрать её из ветки и добавить в .gitignore в корне проекта

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.
Binary file added requirements.txt
Binary file not shown.
13 changes: 13 additions & 0 deletions tests/test_bun.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
from conftest import *
import allure


class TestBun:

@allure.title('Проверка работы метода get_name, который получает название булки')
def test_get_name_bun_success(self, mock_bun):
assert mock_bun.get_name() == Data1.bun_name

@allure.title('Проверка работы метода get_price, который получает стоимость булки')
def test_get_price_bun_success(self, mock_bun_2):
assert mock_bun_2.get_price() == Data2.bun_price
73 changes: 73 additions & 0 deletions tests/test_burger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
from praktikum.burger import Burger
from conftest import *
import pytest
import allure


class TestBurger:
@allure.title('Проверка работы метода set_buns, добавляющего булочку в бургер')
def test_set_buns_success(self, mock_bun):
burger = Burger()
burger.set_buns(mock_bun)
assert burger.bun == mock_bun

@allure.title('Проверка работы метода add_ingredient, добавляющего ингредиенты в бургер')
@allure.description('С помощью параметризации выполняем три теста: проверяем по очереди '
'добавление соуса и двух разных начинок')
@pytest.mark.parametrize('ingredients, added_ingredient', [
[Data1.sauce_name, Data1.sauce_name],
[Data1.filling_name, Data1.filling_name],
[Data2.filling_name, Data2.filling_name]
]
)
def test_add_ingredient_success(self, ingredients, added_ingredient):
burger = Burger()
burger.add_ingredient(ingredients)
assert burger.ingredients == [added_ingredient] and len(burger.ingredients) == 1

@allure.title('Проверка работы метода remove_ingredient, удаляющего ингредиент из бургера')
@allure.description('С помощью параметризации выполняем два теста: проверяем по очереди '
'удаление соуса и начинки')
@pytest.mark.parametrize('ingredients, removed_ingredient', [
[Data1.sauce_name, Data1.sauce_name],
[Data2.filling_name, Data2.filling_name]
]
)
def test_remove_ingredient_success(self, ingredients, removed_ingredient, mock_filling):
burger = Burger()
burger.add_ingredient(mock_filling)
burger.add_ingredient(ingredients)
burger.remove_ingredient(1)
assert removed_ingredient not in burger.ingredients and mock_filling in burger.ingredients

@allure.title('Проверка работы метода move_ingredient, перемещающего ингредиенты в бургере')
def test_move_ingredient_success(self, mock_sauce, mock_filling):
burger = Burger()
burger.add_ingredient(mock_sauce)
burger.add_ingredient(mock_filling)
burger.move_ingredient(0, 1)
assert len(burger.ingredients) == 2
assert burger.ingredients[0] == mock_filling and burger.ingredients[1] == mock_sauce

@allure.title('Проверка работы метода get_price, высчитывающего конечную стоимость бургера')
def test_get_price_burger_success(self, mock_bun_2, mock_sauce_2, mock_filling_2):
burger = Burger()
burger.set_buns(mock_bun_2)
burger.add_ingredient(mock_sauce_2)
burger.add_ingredient(mock_filling_2)
assert burger.get_price() == Data2.burger_final_cost

@allure.title('Проверка работы метода get_receipt, получающего рецепт собранного бургера и его стоимость')
def test_get_receipt_success(self, mock_bun, mock_sauce, mock_filling, mock_filling_2):
burger = Burger()
burger.set_buns(mock_bun)
burger.add_ingredient(mock_sauce)
burger.add_ingredient(mock_filling)
burger.add_ingredient(mock_filling_2)
assert burger.get_receipt() == ('(==== Флюоресцентная булка R2-D3 ====)\n'
'= sauce Соус традиционный галактический =\n'
'= filling Мясо бессмертных моллюсков Protostomia =\n'
'= filling Сыр с астероидной плесенью =\n'
'(==== Флюоресцентная булка R2-D3 ====)\n'
'\n'
f'Price: {burger.get_price()}')
25 changes: 25 additions & 0 deletions tests/test_database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from data import TestDataBase
from conftest import db
import pytest
import allure


class TestDB:
@allure.title('Проверка работы метода available_buns, получающего список доступных булок из базы')
@allure.description('С помощью параметризации выполняем три теста: проверяем по очереди '
'имя и стоимость каждой булки')
@pytest.mark.parametrize('index_bun, bun_name, bun_price', TestDataBase.test_data_base_buns)
def test_available_buns_db_success(self, db, index_bun, bun_name, bun_price):
data_buns = db.available_buns()
assert data_buns[index_bun].get_name() == bun_name and data_buns[index_bun].get_price() == bun_price

@allure.title('Проверка работы метода available_ingredients, получающего список доступных ингредиентов из базы')
@allure.description('С помощью параметризации выполняем шесть тестов: проверяем по очереди '
'имя, тип и стоимость каждого ингредиента')
@pytest.mark.parametrize('index_i, type_ingredient, name_ingredient, price_ingredient',
TestDataBase.test_data_base_ingredients)
def test_available_ingredients_db_success(self, db, index_i, type_ingredient, name_ingredient, price_ingredient):
data_ingredients = db.available_ingredients()
assert (data_ingredients[index_i].get_name() == name_ingredient and
data_ingredients[index_i].get_type() == type_ingredient and
data_ingredients[index_i].get_price() == price_ingredient)
28 changes: 28 additions & 0 deletions tests/test_ingredient.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
from conftest import *
import allure


class TestIngredient:
@allure.title('Проверка работы метода get_name, получающего название соуса')
def test_get_name_sauce_success(self, mock_sauce):
assert mock_sauce.get_name() == Data1.sauce_name

@allure.title('Проверка работы метода get_name, получающего название начинки')
def test_get_name_filling_success(self, mock_filling):
assert mock_filling.get_name() == Data1.filling_name

@allure.title('Проверка работы метода get_price, получающего стоимость соуса')
def test_get_price_sauce_success(self, mock_sauce_2):
assert mock_sauce_2.get_price() == Data2.sauce_price

@allure.title('Проверка работы метода get_price, получающего стоимость начинки')
def test_get_price_filling_success(self, mock_filling_2):
assert mock_filling_2.get_price() == Data2.filling_price

@allure.title('Проверка работы метода get_type, получающего тип ингредиента для соуса')
def test_get_type_sauce_success(self, mock_sauce):
assert mock_sauce.get_type() == Data1.sauce_type

@allure.title('Проверка работы метода get_type, получающего тип ингредиента для начинки')
def test_get_type_filling_success(self, mock_filling):
assert mock_filling.get_type() == Data1.filling_type