Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Improve code style in tests

Marcin Gębala67ac668f6aec
diff --git a/tests/api/test_order.py b/tests/api/test_order.py
index 72a8ab3fca..916d578abe 100644
--- a/tests/api/test_order.py
+++ b/tests/api/test_order.py
@@ -424,7 +424,6 @@ def test_can_finalize_draft_order_non_existing_variant(order_with_lines):
line.refresh_from_db()
assert line.variant is None
- order.refresh_from_db()
errors = can_finalize_draft_order(order, [])
assert (
errors[0].message ==
diff --git a/tests/test_order.py b/tests/test_order.py
index 57b36562eb..b2c605b15c 100644
--- a/tests/test_order.py
+++ b/tests/test_order.py
@@ -3,24 +3,24 @@ from decimal import Decimal
import pytest
from django.urls import reverse
from django_countries.fields import Country
-from measurement.measures import Weight
from prices import Money, TaxedMoney
+from tests.utils import get_redirect_location
from saleor.account.models import User
from saleor.checkout.utils import create_order
from saleor.core.exceptions import InsufficientStock
from saleor.core.utils.taxes import (
DEFAULT_TAX_RATE_NAME, get_tax_rate_by_name, get_taxes_for_country)
+from saleor.core.weight import zero_weight
from saleor.order import FulfillmentStatus, OrderStatus, models
from saleor.order.models import Order
from saleor.order.utils import (
add_variant_to_order, cancel_fulfillment, cancel_order,
change_order_line_quantity, delete_order_line, recalculate_order,
- restock_fulfillment_lines, restock_order_lines, update_order_prices,
- update_order_status)
+ recalculate_order_weight, restock_fulfillment_lines, restock_order_lines,
+ update_order_prices, update_order_status)
from saleor.payment import ChargeStatus
from saleor.payment.models import Payment
-from tests.utils import get_redirect_location
def test_total_setter():
@@ -520,35 +520,30 @@ def test_add_order_note_view(order, authorized_client, customer_user):
def _calculate_order_weight_from_lines(order):
- weight = Weight(kg=0)
+ weight = zero_weight()
for line in order:
weight += line.variant.get_weight() * line.quantity
return weight
-def test_order_weight(order_with_lines):
+def test_calculate_order_weight(order_with_lines):
order_weight = order_with_lines.weight
calculated_weight = _calculate_order_weight_from_lines(order_with_lines)
-
assert calculated_weight == order_weight
def test_order_weight_add_more_variant(order_with_lines):
variant = order_with_lines.lines.first().variant
-
add_variant_to_order(order_with_lines, variant, 2)
order_with_lines.refresh_from_db()
-
assert order_with_lines.weight == _calculate_order_weight_from_lines(
order_with_lines)
def test_order_weight_add_new_variant(order_with_lines, product):
variant = product.variants.first()
-
add_variant_to_order(order_with_lines, variant, 2)
order_with_lines.refresh_from_db()
-
assert order_with_lines.weight == _calculate_order_weight_from_lines(
order_with_lines)
@@ -558,7 +553,6 @@ def test_order_weight_change_line_quantity(order_with_lines):
new_quantity = line.quantity + 2
change_order_line_quantity(line, new_quantity)
order_with_lines.refresh_from_db()
-
assert order_with_lines.weight == _calculate_order_weight_from_lines(
order_with_lines)
@@ -566,7 +560,6 @@ def test_order_weight_change_line_quantity(order_with_lines):
def test_order_weight_delete_line(order_with_lines):
line = order_with_lines.lines.first()
delete_order_line(line)
-
assert order_with_lines.weight == _calculate_order_weight_from_lines(
order_with_lines)