Skip to content

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

Fix remarks

oldPadavan56734b78efda
diff --git a/saleor/graphql/product/mutations/products.py b/saleor/graphql/product/mutations/products.py
index b3af3b94ee..eb135aa648 100644
--- a/saleor/graphql/product/mutations/products.py
+++ b/saleor/graphql/product/mutations/products.py
@@ -448,7 +448,7 @@ class ProductImageCreate(ModelMutation):
def clean_input(cls, info, instance, input, errors):
cleaned_input = super().clean_input(info, instance, input, errors)
uploaded_image = cleaned_input['image']
- if not uploaded_image.content_type.startswith('image'):
+ if not uploaded_image.content_type.startswith('image/'):
cls.add_error(errors, 'image', 'Invalid file type')
return cleaned_input
@@ -457,7 +457,7 @@ class ProductImageCreate(ModelMutation):
return user.has_perm('product.edit_product')
-class ProductImageUpdate(ModelMutation):
+class ProductImageUpdate(ProductImageCreate):
class Arguments:
id = graphene.ID(
required=True, description='ID of a product image to update.')
@@ -469,18 +469,6 @@ class ProductImageUpdate(ModelMutation):
description = 'Updates a product image.'
model = models.ProductImage
- @classmethod
- def clean_input(cls, info, instance, input, errors):
- cleaned_input = super().clean_input(info, instance, input, errors)
- uploaded_image = cleaned_input['image']
- if not uploaded_image.content_type.startswith('image'):
- cls.add_error(errors, 'image', 'Invalid file type')
- return cleaned_input
-
- @classmethod
- def user_is_allowed(cls, user, input):
- return user.has_perm('product.edit_product')
-
class ProductImageReorder(BaseMutation):
class Arguments:
diff --git a/tests/api/test_product.py b/tests/api/test_product.py
index ea4bb5f282..42b529c395 100644
--- a/tests/api/test_product.py
+++ b/tests/api/test_product.py
@@ -891,8 +891,8 @@ def test_invalid_product_image_update_mutation(
admin_api_client, product_with_image):
product = product_with_image
query = """
- mutation updateProductImage($image: Upload!, $alt: String, $product: ID!) {
- productImageCreate(input: {image: $image, alt: $alt, product: $product}) {
+ mutation updateProductImage($image: Upload!, $alt: String, $product: ID!, $id: ID!) {
+ productImageUpdate(id: $id, input: {image: $image, alt: $alt, product: $product}) {
productImage {
image
}
@@ -908,12 +908,14 @@ def test_invalid_product_image_update_mutation(
new_image_file, new_image_name = create_pdf_file_with_image_ext()
variables = {
'product': graphene.Node.to_global_id('Product', product.id),
- 'image': new_image_name}
+ 'image': new_image_name,
+ 'id': graphene.Node.to_global_id('ProductImage', image_obj.id),
+ }
body = get_multipart_request_body(
query, variables, new_image_file, new_image_name)
response = admin_api_client.post_multipart(reverse('api'), body)
content = get_graphql_content(response)
- assert content['data']['productImageCreate']['errors'] == [{
+ assert content['data']['productImageUpdate']['errors'] == [{
'field': 'image',
'message': 'Invalid file type'}]
product_with_image.refresh_from_db()