Created
January 3, 2021 17:11
-
-
Save klement97/2868aab6f56cbf54afa2a7bdede19105 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pytest | |
from order.models import Pizza, Topping | |
@pytest.mark.django_db | |
def test_pizza_price_with_toppings(): | |
# Preparation phase | |
pizza = Pizza.objects.create(name='Margarita') | |
topping1 = Topping.objects.create(description='Pizza sauce', price=1.5) | |
topping2 = Topping.objects.create(description='Mozzarella', price=1.65) | |
pizza.toppings.add(topping1) | |
pizza.toppings.add(topping2) | |
# Calculating results | |
actual_price = float(pizza.total_price) | |
expected_price = topping1.price + topping2.price | |
# Assertion | |
assert actual_price == expected_price | |
@pytest.mark.django_db | |
def test_pizza_price_without_toppings(): | |
# Preparation phase | |
pizza = Pizza.objects.create(name='Supreme') | |
# Calculating results | |
actual_price = float(pizza.total_price) | |
expected_price = 0 | |
# Assertion | |
assert actual_price == expected_price |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment