Repository: saleor/saleor

Issue:
Weight type should use WeightUnitsEnum
### What I'm trying to achieve
To have `Weight` type defined as
```graphql
type Weight {
  unit: WeightUnitsEnum!
  value: Float!
}
```
to maintain consistency with `Shop.defaultWeightUnit` field.


Discussion:

Resolving patch:
diff --git a/saleor/graphql/core/types/common.py b/saleor/graphql/core/types/common.py
--- a/saleor/graphql/core/types/common.py
+++ b/saleor/graphql/core/types/common.py
@@ -26,6 +26,7 @@
     TranslationErrorCode,
     WarehouseErrorCode,
     WebhookErrorCode,
+    WeightUnitsEnum,
     WishlistErrorCode,
 )
 from .money import VAT
@@ -231,7 +232,7 @@ class SeoInput(graphene.InputObjectType):
 
 
 class Weight(graphene.ObjectType):
-    unit = graphene.String(description="Weight unit.", required=True)
+    unit = WeightUnitsEnum(description="Weight unit.", required=True)
     value = graphene.Float(description="Weight value.", required=True)
 
     class Meta:


Test patch:
diff --git a/saleor/graphql/product/tests/test_product.py b/saleor/graphql/product/tests/test_product.py
--- a/saleor/graphql/product/tests/test_product.py
+++ b/saleor/graphql/product/tests/test_product.py
@@ -29,7 +29,7 @@
 from ....product.tests.utils import create_image, create_pdf_file_with_image_ext
 from ....product.utils.attributes import associate_attribute_values_to_instance
 from ....warehouse.models import Allocation, Stock, Warehouse
-from ...core.enums import ReportingPeriod
+from ...core.enums import ReportingPeriod, WeightUnitsEnum
 from ...tests.utils import (
     assert_no_permission,
     get_graphql_content,
@@ -4281,14 +4281,14 @@ def test_update_or_create_variant_stocks_empty_stocks_data(variant, warehouses):
 @pytest.mark.parametrize(
     "weight, expected_weight_value, expected_weight_unit",
     (
-        ("0", 0, "kg"),
-        (0, 0, "kg"),
-        (11.11, 11.11, "kg"),
-        (11, 11.0, "kg"),
-        ("11.11", 11.11, "kg"),
-        ({"value": 11.11, "unit": "kg"}, 11.11, "kg",),
-        ({"value": 11, "unit": "g"}, 11.0, "g",),
-        ({"value": "11.11", "unit": "ounce"}, 11.11, "oz",),
+        ("0", 0, WeightUnitsEnum.KG.name),
+        (0, 0, WeightUnitsEnum.KG.name),
+        (11.11, 11.11, WeightUnitsEnum.KG.name),
+        (11, 11.0, WeightUnitsEnum.KG.name),
+        ("11.11", 11.11, WeightUnitsEnum.KG.name),
+        ({"value": 11.11, "unit": "kg"}, 11.11, WeightUnitsEnum.KG.name,),
+        ({"value": 11, "unit": "g"}, 11.0, WeightUnitsEnum.G.name,),
+        ({"value": "11.11", "unit": "ounce"}, 11.11, WeightUnitsEnum.OZ.name,),
     ),
 )
 def test_create_product_with_weight_variable(
@@ -4326,14 +4326,14 @@ def test_create_product_with_weight_variable(
 @pytest.mark.parametrize(
     "weight, expected_weight_value, expected_weight_unit",
     (
-        ("0", 0, "kg"),
-        (0, 0, "kg"),
-        ("11.11", 11.11, "kg"),
-        ("11", 11.0, "kg"),
-        ('"11.11"', 11.11, "kg"),
-        ('{value: 11.11, unit: "kg"}', 11.11, "kg",),
-        ('{value: 11, unit: "g"}', 11.0, "g",),
-        ('{value: "11.11", unit: "ounce"}', 11.11, "oz",),
+        ("0", 0, WeightUnitsEnum.KG.name),
+        (0, 0, WeightUnitsEnum.KG.name),
+        ("11.11", 11.11, WeightUnitsEnum.KG.name),
+        ("11", 11.0, WeightUnitsEnum.KG.name),
+        ('"11.11"', 11.11, WeightUnitsEnum.KG.name),
+        ('{value: 11.11, unit: "kg"}', 11.11, WeightUnitsEnum.KG.name,),
+        ('{value: 11, unit: "g"}', 11.0, WeightUnitsEnum.G.name,),
+        ('{value: "11.11", unit: "ounce"}', 11.11, WeightUnitsEnum.OZ.name,),
     ),
 )
 def test_create_product_with_weight_input(
diff --git a/saleor/graphql/product/tests/test_variant.py b/saleor/graphql/product/tests/test_variant.py
--- a/saleor/graphql/product/tests/test_variant.py
+++ b/saleor/graphql/product/tests/test_variant.py
@@ -9,6 +9,7 @@
 from ....product.utils.attributes import associate_attribute_values_to_instance
 from ....warehouse.error_codes import StockErrorCode
 from ....warehouse.models import Stock, Warehouse
+from ...core.enums import WeightUnitsEnum
 from ...tests.utils import get_graphql_content
 
 
@@ -170,7 +171,7 @@ def test_create_variant(
     assert data["sku"] == sku
     assert data["attributes"][0]["attribute"]["slug"] == variant_slug
     assert data["attributes"][0]["values"][0]["slug"] == variant_value
-    assert data["weight"]["unit"] == "kg"
+    assert data["weight"]["unit"] == WeightUnitsEnum.KG.name
     assert data["weight"]["value"] == weight
     assert len(data["stocks"]) == 1
     assert data["stocks"][0]["quantity"] == stocks[0]["quantity"]
diff --git a/saleor/graphql/shipping/tests/test_shipping_method.py b/saleor/graphql/shipping/tests/test_shipping_method.py
--- a/saleor/graphql/shipping/tests/test_shipping_method.py
+++ b/saleor/graphql/shipping/tests/test_shipping_method.py
@@ -3,6 +3,7 @@
 
 from ....shipping.error_codes import ShippingErrorCode
 from ....shipping.utils import get_countries_without_shipping_zone
+from ...core.enums import WeightUnitsEnum
 from ...tests.utils import get_graphql_content
 from ..types import ShippingMethodTypeEnum
 
@@ -616,8 +617,13 @@ def test_create_price_shipping_method_errors(
 @pytest.mark.parametrize(
     "min_weight, max_weight, expected_min_weight, expected_max_weight",
     (
-        (10.32, 15.64, {"value": 10.32, "unit": "kg"}, {"value": 15.64, "unit": "kg"}),
-        (10.92, None, {"value": 10.92, "unit": "kg"}, None),
+        (
+            10.32,
+            15.64,
+            {"value": 10.32, "unit": WeightUnitsEnum.KG.name},
+            {"value": 15.64, "unit": WeightUnitsEnum.KG.name},
+        ),
+        (10.92, None, {"value": 10.92, "unit": WeightUnitsEnum.KG.name}, None),
     ),
 )
 def test_create_weight_based_shipping_method(