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.
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,15 @@

### Структура проекта

- `praktikum` - пакет, содержащий код программы
- `tests` - пакет, содержащий тесты, разделенные по классам. Например, `bun_test.py`, `burger_test.py` и т.д.
`praktikum` - пакет, содержащий код программы
`tests` - пакет, содержащий тесты, разделенные по классам. Например, `bun_test.py`, `burger_test.py` и т.д.

### Запуск автотестов

**Установка зависимостей**

> `$ pip install -r requirements.txt`
`$ pip install -r requirements.txt`

**Запуск автотестов и создание HTML-отчета о покрытии**

> `$ pytest --cov=praktikum --cov-report=html`
`$ pytest --cov=praktikum --cov-report=html`
Binary file added __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.

Нужно исправить: из финального проекта нужно удалить все файлы и папки, которые не относятся к решению задачи

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.
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
133 changes: 133 additions & 0 deletions coverage.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<?xml version="1.0" ?>
<coverage version="7.15.4" timestamp="1787165521823" lines-valid="89" lines-covered="88" line-rate="0.9888" branches-covered="0" branches-valid="0" branch-rate="0" complexity="0">
<!-- Generated by coverage.py: https://coverage.readthedocs.io/en/7.15.4 -->
<!-- Based on https://raw.githubusercontent.com/cobertura/web/master/htdocs/xml/coverage-04.dtd -->
<sources>
<source>/Users/tim/Diplom/qa-python-project</source>
</sources>
<packages>
<package name="." line-rate="0.9888" branch-rate="0" complexity="0">
<classes>
<class name="bun.py" filename="bun.py" complexity="0" line-rate="1" branch-rate="0">
<methods/>
<lines>
<line number="1" hits="1"/>
<line number="7" hits="1"/>
<line number="8" hits="1"/>
<line number="9" hits="1"/>
<line number="11" hits="1"/>
<line number="12" hits="1"/>
<line number="14" hits="1"/>
<line number="15" hits="1"/>
</lines>
</class>
<class name="burger.py" filename="burger.py" complexity="0" line-rate="1" branch-rate="0">
<methods/>
<lines>
<line number="1" hits="1"/>
<line number="3" hits="1"/>
<line number="4" hits="1"/>
<line number="7" hits="1"/>
<line number="15" hits="1"/>
<line number="16" hits="1"/>
<line number="17" hits="1"/>
<line number="19" hits="1"/>
<line number="20" hits="1"/>
<line number="22" hits="1"/>
<line number="23" hits="1"/>
<line number="25" hits="1"/>
<line number="26" hits="1"/>
<line number="28" hits="1"/>
<line number="29" hits="1"/>
<line number="31" hits="1"/>
<line number="32" hits="1"/>
<line number="34" hits="1"/>
<line number="35" hits="1"/>
<line number="37" hits="1"/>
<line number="39" hits="1"/>
<line number="40" hits="1"/>
<line number="42" hits="1"/>
<line number="43" hits="1"/>
<line number="45" hits="1"/>
<line number="46" hits="1"/>
<line number="48" hits="1"/>
</lines>
</class>
<class name="database.py" filename="database.py" complexity="0" line-rate="1" branch-rate="0">
<methods/>
<lines>
<line number="1" hits="1"/>
<line number="3" hits="1"/>
<line number="4" hits="1"/>
<line number="5" hits="1"/>
<line number="8" hits="1"/>
<line number="13" hits="1"/>
<line number="14" hits="1"/>
<line number="15" hits="1"/>
<line number="17" hits="1"/>
<line number="18" hits="1"/>
<line number="19" hits="1"/>
<line number="21" hits="1"/>
<line number="22" hits="1"/>
<line number="23" hits="1"/>
<line number="25" hits="1"/>
<line number="26" hits="1"/>
<line number="27" hits="1"/>
<line number="29" hits="1"/>
<line number="30" hits="1"/>
<line number="32" hits="1"/>
<line number="33" hits="1"/>
</lines>
</class>
<class name="ingredient.py" filename="ingredient.py" complexity="0" line-rate="1" branch-rate="0">
<methods/>
<lines>
<line number="1" hits="1"/>
<line number="8" hits="1"/>
<line number="9" hits="1"/>
<line number="10" hits="1"/>
<line number="11" hits="1"/>
<line number="13" hits="1"/>
<line number="14" hits="1"/>
<line number="16" hits="1"/>
<line number="17" hits="1"/>
<line number="19" hits="1"/>
<line number="20" hits="1"/>
</lines>
</class>
<class name="ingredient_types.py" filename="ingredient_types.py" complexity="0" line-rate="1" branch-rate="0">
<methods/>
<lines>
<line number="6" hits="1"/>
<line number="7" hits="1"/>
</lines>
</class>
<class name="praktikum.py" filename="praktikum.py" complexity="0" line-rate="0.95" branch-rate="0">
<methods/>
<lines>
<line number="1" hits="1"/>
<line number="3" hits="1"/>
<line number="4" hits="1"/>
<line number="5" hits="1"/>
<line number="6" hits="1"/>
<line number="9" hits="1"/>
<line number="11" hits="1"/>
<line number="14" hits="1"/>
<line number="17" hits="1"/>
<line number="20" hits="1"/>
<line number="23" hits="1"/>
<line number="25" hits="1"/>
<line number="26" hits="1"/>
<line number="27" hits="1"/>
<line number="28" hits="1"/>
<line number="31" hits="1"/>
<line number="34" hits="1"/>
<line number="37" hits="1"/>
<line number="40" hits="1"/>
<line number="41" hits="0"/>
</lines>
</class>
</classes>
</package>
</packages>
</coverage>
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
8 changes: 4 additions & 4 deletions praktikum.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from typing import List

from praktikum.bun import Bun
from praktikum.burger import Burger
from praktikum.database import Database
from praktikum.ingredient import Ingredient
from bun import Bun
from burger import Burger
from database import Database
from ingredient import Ingredient


def main():
Expand Down
3 changes: 3 additions & 0 deletions pytest.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[pytest]
addopts = --cov=bun --cov=burger --cov=database --cov=ingredient --cov=ingredient_types --cov=praktikum --cov-report=term-missing --cov-report=xml
python_files = tests/test_*.py
2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
pytest>=8.0
pytest-cov>=4.0
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
102 changes: 102 additions & 0 deletions tests/test_burger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
import pytest
from unittest.mock import Mock

from burger import Burger
from ingredient import Ingredient


def test_burger_init_sets_empty_state():
burger = Burger()

assert burger.bun is None
assert burger.ingredients == []


def test_set_buns_assigns_bun_object():
bun = Mock(get_name=Mock(return_value="plain bun"), get_price=Mock(return_value=100.0))
burger = Burger()

burger.set_buns(bun)

assert burger.bun is bun


def test_add_ingredient_appends_ingredient_to_list():
ingredient = Ingredient("FILLING", "cutlet", 35.0)
burger = Burger()

burger.add_ingredient(ingredient)

assert burger.ingredients == [ingredient]


def test_remove_ingredient_deletes_item_by_index():
first = Ingredient("SAUCE", "hot sauce", 10.0)
second = Ingredient("FILLING", "cutlet", 35.0)
burger = Burger()
burger.add_ingredient(first)
burger.add_ingredient(second)

burger.remove_ingredient(0)

assert burger.ingredients == [second]


@pytest.mark.parametrize(
"ingredient_prices,expected_total",
[
([100.0], 300.0),
([10.0, 20.0], 230.0),
([5.0, 15.0, 25.0], 245.0),
],
)
def test_get_price_includes_bun_twice_and_all_ingredient_prices(
ingredient_prices, expected_total
):
# Мокаем булочку и ингредиенты, чтобы тест был независим от реализации Ingredient.
bun = Mock(get_name=Mock(return_value="mock bun"), get_price=Mock(return_value=100.0))
burger = Burger()
burger.set_buns(bun)

for price in ingredient_prices:
ingredient = Mock(get_price=Mock(return_value=price))
burger.add_ingredient(ingredient)

assert burger.get_price() == expected_total


@pytest.mark.parametrize(
"initial_names,move_from,move_to,expected_names",
[
(["hot sauce", "cutlet", "sausage"], 2, 0, ["sausage", "hot sauce", "cutlet"]),
(["sour cream", "dinosaur", "cutlet"], 0, 2, ["dinosaur", "cutlet", "sour cream"]),
],
)
def test_move_ingredient_reorders_list_correctly(
initial_names, move_from, move_to, expected_names
):
burger = Burger()

for name in initial_names:
burger.add_ingredient(Ingredient("FILLING", name, 1.0))

burger.move_ingredient(move_from, move_to)
assert [ingredient.get_name() for ingredient in burger.ingredients] == expected_names


def test_get_receipt_outputs_bun_and_ingredient_lines():
bun = Mock(get_name=Mock(return_value="test bun"), get_price=Mock(return_value=50.0))
ingredient = Mock(
get_type=Mock(return_value="SAUCE"),
get_name=Mock(return_value="hot sauce"),
get_price=Mock(return_value=10.0),
)
burger = Burger()
burger.set_buns(bun)
burger.add_ingredient(ingredient)

receipt = burger.get_receipt()

assert "(==== test bun ====)" in receipt
assert "= sauce hot sauce =" in receipt
assert "Price: 110.0" in receipt

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

нужно протестировать все методы бургера

45 changes: 45 additions & 0 deletions tests/test_database.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
from database import Database


def test_available_buns_returns_three_items():
database = Database()
buns = database.available_buns()

assert len(buns) == 3


def test_available_buns_returns_expected_bun_names():
database = Database()
buns = database.available_buns()

assert buns[0].get_name() == "black bun"
assert buns[1].get_name() == "white bun"
assert buns[2].get_name() == "red bun"


def test_available_buns_contains_expected_bun_price():
database = Database()
buns = database.available_buns()

assert buns[1].get_price() == 200


def test_available_ingredients_returns_six_items():
database = Database()
ingredients = database.available_ingredients()

assert len(ingredients) == 6


def test_available_ingredients_returns_sauce_and_filling_types():
database = Database()
ingredients = database.available_ingredients()

assert {ingredient.get_type() for ingredient in ingredients} == {"SAUCE", "FILLING"}


def test_available_ingredients_contains_cutlet():
database = Database()
ingredients = database.available_ingredients()

assert any(ingredient.get_name() == "cutlet" for ingredient in ingredients)
Loading