Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Test convert weight
Pacu2311e0346c45d
diff --git a/saleor/core/weight.py b/saleor/core/weight.pyindex 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.pyindex 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, ModelMutationfrom ...core.types.common import Decimal, SeoInputfrom ...core.utils import clean_seo_fieldsfrom ...file_upload.types import Upload-from ...utils import get_attributes_dict_from_listfrom ...shipping.types import WeightScalar+from ...utils import get_attributes_dict_from_listfrom ..types import Collection, Product, ProductImage, ProductVariantdiff --git a/tests/test_core.py b/tests/test_core.pyindex 981bd22c38..405edea56b 100644--- a/tests/test_core.py+++ b/tests/test_core.py@@ -3,18 +3,20 @@ from contextlib import redirect_stdoutfrom unittest.mock import Mock, patchimport pytest+from django.conf import settingsfrom django.db.models import Case, F, Whenfrom django.shortcuts import reversefrom django.urls import translate_url+from measurement.measures import Weightfrom prices import Money-from saleor.account.models import Address, Userfrom saleor.core.storages import S3MediaStoragefrom 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_weightfrom saleor.discount.models import Sale, Voucherfrom saleor.order.models import Orderfrom 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