Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Fix review remarks and codeclimate issues
oldPadavan9541085c2210
diff --git a/saleor/graphql/product/mutations/products.py b/saleor/graphql/product/mutations/products.pyindex 77baa4e24e..3c03333e3b 100644--- a/saleor/graphql/product/mutations/products.py+++ b/saleor/graphql/product/mutations/products.py@@ -332,7 +332,7 @@ class ProductVariantCreate(ModelMutation):model = models.ProductVariant@classmethod- def check_all_product_type_attributes_provided(+ def clean_product_type_attributes(cls, attributes_qs, attributes_input, errors):product_type_attr_slugs = {attr.slug for attr in attributes_qs}attributes_input = {attr.slug for attr in attributes_input}@@ -343,8 +343,9 @@ class ProductVariantCreate(ModelMutation):'Missing attributes: %s' % ', '.join(missing_attributes))@classmethod- def clean_input(- cls, info, instance, input, errors, check_all_attrs_provided=True):+ def get_cleaned_input(+ cls, info, instance, input, errors,+ check_if_all_attrs_provided=True):cleaned_input = super().clean_input(info, instance, input, errors)# Attributes are provided as list of `AttributeValueInput` objects.@@ -360,9 +361,8 @@ class ProductVariantCreate(ModelMutation):if attributes and product_type:try:qs = product_type.variant_attributes.prefetch_related('values')- if check_all_attrs_provided:- cls.check_all_product_type_attributes_provided(- qs, attributes, errors)+ if check_if_all_attrs_provided:+ cls.clean_product_type_attributes(qs, attributes, errors)attributes = attributes_to_hstore(attributes, qs)except ValueError as e:cls.add_error(errors, 'attributes', str(e))@@ -370,6 +370,11 @@ class ProductVariantCreate(ModelMutation):cleaned_input['attributes'] = attributesreturn cleaned_input+ @classmethod+ def clean_input(cls, info, instance, input, errors):+ return cls.get_cleaned_input(+ info, instance, input, errors, check_if_all_attrs_provided=True)+@classmethoddef save(cls, info, instance, cleaned_input):attributes = instance.product.product_type.variant_attributes.all()@@ -395,8 +400,8 @@ class ProductVariantUpdate(ProductVariantCreate):@classmethoddef clean_input(cls, info, instance, input, errors):- return super(ProductVariantUpdate, cls).clean_input(- info, instance, input, errors, check_all_attrs_provided=False)+ return super().get_cleaned_input(+ info, instance, input, errors, check_if_all_attrs_provided=False)class ProductVariantDelete(ModelDeleteMutation):diff --git a/tests/api/test_variant.py b/tests/api/test_variant.pyindex eaf41d0d4f..770f6b3c63 100644--- a/tests/api/test_variant.py+++ b/tests/api/test_variant.py@@ -156,22 +156,12 @@ def test_create_product_variant_not_all_attributes(mutation createVariant ($productId: ID!,$sku: String!,- $priceOverride: Decimal,- $costPrice: Decimal,- $quantity: Int!,- $attributes: [AttributeValueInput],- $weight: WeightScalar,- $trackInventory: Boolean!) {+ $attributes: [AttributeValueInput]!) {productVariantCreate(input: {product: $productId,sku: $sku,- priceOverride: $priceOverride,- costPrice: $costPrice,- quantity: $quantity,- attributes: $attributes,- trackInventory: $trackInventory,- weight: $weight+ attributes: $attributes}) {errors {field@@ -179,30 +169,7 @@ def test_create_product_variant_not_all_attributes(}productVariant {name- sku- attributes {- attribute {- slug- }- value {- slug- }- }- quantity- priceOverride {- currency- amount- localized- }- costPrice {- currency- amount- localized- }- weight {- value- unit- }+ sku}}}@@ -210,10 +177,6 @@ def test_create_product_variant_not_all_attributes("""product_id = graphene.Node.to_global_id('Product', product.pk)sku = "1"- price_override = 1.32- cost_price = 3.22- quantity = 10- weight = 10.22variant_slug = product_type.variant_attributes.first().slugvariant_value = 'test-value'product_type.variant_attributes.add(color_attribute)@@ -221,13 +184,7 @@ def test_create_product_variant_not_all_attributes(variables = json.dumps({'productId': product_id,'sku': sku,- 'quantity': quantity,- 'costPrice': cost_price,- 'priceOverride': price_override,- 'weight': weight,- 'attributes': [- {'slug': variant_slug, 'value': variant_value}],- 'trackInventory': True})+ 'attributes': [{'slug': variant_slug, 'value': variant_value}]})response = admin_api_client.post(reverse('api'), {'query': query, 'variables': variables})content = get_graphql_content(response)