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
119 changes: 119 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
*.py,cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Django stuff:
*.log
local_settings.py
db.sqlite3
db.sqlite3-journal

# Flask stuff:
instance/
.webassets-cache

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# Jupyter Notebook
.ipynb_checkpoints

# IPython
profile_default/
ipython_config.py

# pyenv
.python-version

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
.sage.py

# Environments
.env
.venv
env/
venv/
ENV/
env.bak/
venv.bak/

# Spyder project settings
.spyderproject
.spyderworkspace

# Rope project settings
.ropeproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

# Ignore the symbolic link
praktikum
Empty file removed __init__.py
Empty file.
15 changes: 0 additions & 15 deletions bun.py

This file was deleted.

48 changes: 0 additions & 48 deletions burger.py

This file was deleted.

19 changes: 19 additions & 0 deletions data.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from praktikum.bun import Bun
from praktikum.ingredient import Ingredient
from praktikum.ingredient_types import INGREDIENT_TYPE_SAUCE, INGREDIENT_TYPE_FILLING

class Data:
BUNS = [
Bun("black bun", 100),
Bun("white bun", 200),
Bun("red bun", 300)
]

INGREDIENTS = [
Ingredient(INGREDIENT_TYPE_SAUCE, "hot sauce", 100),
Ingredient(INGREDIENT_TYPE_SAUCE, "sour cream", 200),
Ingredient(INGREDIENT_TYPE_SAUCE, "chili sauce", 300),
Ingredient(INGREDIENT_TYPE_FILLING, "cutlet", 100),
Ingredient(INGREDIENT_TYPE_FILLING, "dinosaur", 200),
Ingredient(INGREDIENT_TYPE_FILLING, "sausage", 300)
]
33 changes: 0 additions & 33 deletions database.py

This file was deleted.

20 changes: 0 additions & 20 deletions ingredient.py

This file was deleted.

7 changes: 0 additions & 7 deletions ingredient_types.py

This file was deleted.

File renamed without changes.
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
22 changes: 22 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import pytest
from unittest.mock import patch
from praktikum.bun import Bun
from praktikum.ingredient import Ingredient
from praktikum.ingredient_types import INGREDIENT_TYPE_SAUCE, INGREDIENT_TYPE_FILLING

@pytest.fixture()
def mock_random_choice():
with patch('random.choice') as mocked_choice:
yield mocked_choice

@pytest.fixture
def bun():
return Bun("black bun", 100)

@pytest.fixture
def ingredient_sauce():
return Ingredient(INGREDIENT_TYPE_SAUCE, "hot sauce", 100)

@pytest.fixture
def ingredient_filling():
return Ingredient(INGREDIENT_TYPE_FILLING, "cutlet", 200)
10 changes: 10 additions & 0 deletions tests/test_bun.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from praktikum.bun import Bun

class TestBun:
def test_get_name(self):
bun = Bun("black bun", 100)
assert bun.get_name() == "black bun"

def test_get_price(self):
bun = Bun("black bun", 100)
assert bun.get_price() == 100
49 changes: 49 additions & 0 deletions tests/test_burger.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import pytest
from praktikum.burger import Burger

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

class TestBurger:
def test_set_buns(self, burger, bun):
burger.set_buns(bun)
assert burger.bun == bun

def test_add_ingredient(self, burger, ingredient_sauce):
burger.add_ingredient(ingredient_sauce)
assert len(burger.ingredients) == 1
assert burger.ingredients[0] == ingredient_sauce

def test_remove_ingredient(self, burger, ingredient_sauce, ingredient_filling):
burger.add_ingredient(ingredient_sauce)
burger.add_ingredient(ingredient_filling)
burger.remove_ingredient(0)
assert len(burger.ingredients) == 1
assert burger.ingredients[0] == ingredient_filling

def test_move_ingredient(self, burger, ingredient_sauce, ingredient_filling):
burger.add_ingredient(ingredient_sauce)
burger.add_ingredient(ingredient_filling)
burger.move_ingredient(0, 1)
assert burger.ingredients[0] == ingredient_filling
assert burger.ingredients[1] == ingredient_sauce

def test_get_price(self, burger, bun, ingredient_sauce, ingredient_filling):
burger.set_buns(bun)
burger.add_ingredient(ingredient_sauce)
burger.add_ingredient(ingredient_filling)
expected_price = bun.get_price() * 2 + ingredient_sauce.get_price() + ingredient_filling.get_price()
assert burger.get_price() == expected_price

def test_get_receipt(self, burger, bun, ingredient_sauce, ingredient_filling):
burger.set_buns(bun)
burger.add_ingredient(ingredient_sauce)
burger.add_ingredient(ingredient_filling)

receipt = burger.get_receipt()

assert bun.get_name() in receipt
assert ingredient_sauce.get_name() in receipt
assert ingredient_filling.get_name() in receipt
assert str(burger.get_price()) in 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 @@
from unittest.mock import patch
from praktikum.database import Database

class TestDatabase:
def test_available_buns(self, mock_random_choice):
db = Database()
mock_bun = db.buns[0]
mock_random_choice.return_value = mock_bun
bun = db.available_buns()
assert bun == mock_bun

def test_available_ingredients(self, mock_random_choice):
db = Database()
mock_ingredient = db.ingredients[0]
mock_random_choice.return_value = mock_ingredient
ingredient = db.available_ingredients()
assert ingredient == mock_ingredient
15 changes: 15 additions & 0 deletions tests/test_ingredient.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import pytest
from praktikum.ingredient import Ingredient
from praktikum.ingredient_types import INGREDIENT_TYPE_SAUCE, INGREDIENT_TYPE_FILLING

class TestIngredient:
@pytest.mark.parametrize("expected_type, expected_name, expected_price", [
(INGREDIENT_TYPE_SAUCE, "hot sauce", 100),
(INGREDIENT_TYPE_FILLING, "cutlet", 200),
(INGREDIENT_TYPE_SAUCE, "chili sauce", 300.5)
])
def test_getters(self, expected_type, expected_name, expected_price):
ingredient = Ingredient(expected_type, expected_name, expected_price)
assert ingredient.get_type() == expected_type
assert ingredient.get_name() == expected_name
assert ingredient.get_price() == expected_price