Skip to content

Instantly share code, notes, and snippets.

@klement97
Created January 4, 2021 21:12
Show Gist options
  • Save klement97/6a7743b0ceaa885f4312504358315a92 to your computer and use it in GitHub Desktop.
Save klement97/6a7743b0ceaa885f4312504358315a92 to your computer and use it in GitHub Desktop.
@pytest.mark.django_db
def test_pizza_price_with_toppings():
# Preparation phase
pizza = create_pizza(number_of_toppings=2)
# Calculating results
actual_price = pizza.total_price
expected_price = sum([t.price for t in pizza.toppings.all()])
# Assertion
assert actual_price == expected_price
@pytest.mark.django_db
def test_pizza_price_without_toppings():
# Preparation phase
pizza = create_pizza(number_of_toppings=0)
# Calculating results
actual_price = pizza.total_price
expected_price = Decimal(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