Skip to content

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

Test convert weight

Pacu2311e0346c45d
diff --git a/saleor/core/weight.py b/saleor/core/weight.py
index c9af44b274..6166b5b1e5 100644
--- a/saleor/core/weight.py
+++ b/saleor/core/weight.py
@@ -74,7 +74,7 @@ class WeightInput(forms.TextInput):
class WeightField(forms.DecimalField):
- def __init__(self, widget=WeightInput, min_value=0, *args, **kwargs):
+ def __init__(self, *args, widget=WeightInput, min_value=0, **kwargs):
if isinstance(widget, type):
widget = widget(attrs={'type': 'number', 'step': 'any'})
super().__init__(*args, widget=widget, **kwargs)
diff --git a/saleor/graphql/product/mutations/products.py b/saleor/graphql/product/mutations/products.py
index 2b0dfd517b..e8c0cd05be 100644
--- a/saleor/graphql/product/mutations/products.py
+++ b/saleor/graphql/product/mutations/products.py
@@ -9,8 +9,8 @@ from ...core.mutations import BaseMutation, ModelDeleteMutation, ModelMutation
from ...core.types.common import Decimal, SeoInput
from ...core.utils import clean_seo_fields
from ...file_upload.types import Upload
-from ...utils import get_attributes_dict_from_list
from ...shipping.types import WeightScalar
+from ...utils import get_attributes_dict_from_list
from ..types import Collection, Product, ProductImage, ProductVariant
diff --git a/tests/test_core.py b/tests/test_core.py
index 981bd22c38..405edea56b 100644
--- a/tests/test_core.py
+++ b/tests/test_core.py
@@ -3,18 +3,20 @@ from contextlib import redirect_stdout
from unittest.mock import Mock, patch
import pytest
+
from django.conf import settings
from django.db.models import Case, F, When
from django.shortcuts import reverse
from django.urls import translate_url
+from measurement.measures import Weight
from prices import Money
-
from saleor.account.models import Address, User
from saleor.core.storages import S3MediaStorage
from saleor.core.utils import (
Country, create_superuser, create_thumbnails, format_money,
get_country_by_ip, get_currency_for_country, random_data)
from saleor.core.utils.text import get_cleaner, strip_html
+from saleor.core.weight import WeightUnits, convert_weight
from saleor.discount.models import Sale, Voucher
from saleor.order.models import Order
from saleor.product.models import Product, ProductImage, ProductVariant
@@ -291,3 +293,9 @@ def test_set_language_redirects_to_current_endpoint(client):
# now check if we got redirect the endpoint we wanted to go back
# in the new language (cart:index)
assert expected_url == new_url
+
+
+def test_convert_weight():
+ weight = Weight(kg=1)
+ expected_result = Weight(g=1000)
+ assert convert_weight(weight, WeightUnits.GRAM) == expected_result