Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add backgroundImage field to Category mutations
oldPadavan6eee5ac98bb0
diff --git a/saleor/graphql/product/mutations/products.py b/saleor/graphql/product/mutations/products.pyindex 2d2557e394..b8fc820a9d 100644--- a/saleor/graphql/product/mutations/products.py+++ b/saleor/graphql/product/mutations/products.py@@ -24,6 +24,7 @@ class CategoryInput(graphene.InputObjectType):category.''', name='parent')slug = graphene.String(description='Category slug')seo = SeoInput(description='Search engine optimization fields.')+ background_image = Upload(description='Background image file.')class CategoryCreate(ModelMutation):diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex 1ae0d5d0e8..c2af2d3946 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -272,6 +272,7 @@ input CategoryInput {parent: IDslug: Stringseo: SeoInput+ backgroundImage: Upload}type CategoryUpdate {diff --git a/tests/api/test_category.py b/tests/api/test_category.pyindex 6962ecf4ad..ad94a3f1e7 100644--- a/tests/api/test_category.py+++ b/tests/api/test_category.py@@ -3,7 +3,8 @@ import pytestimport graphenefrom django.template.defaultfilters import slugifyfrom saleor.product.models import Category-from tests.api.utils import get_graphql_content+from tests.utils import create_image+from tests.api.utils import get_graphql_content, get_multipart_request_bodydef test_category_query(user_api_client, product):@@ -46,12 +47,13 @@ def test_category_query(user_api_client, product):def test_category_create_mutation(staff_api_client, permission_manage_products):query = """- mutation($name: String, $slug: String, $description: String, $parentId: ID) {+ mutation($name: String, $slug: String, $description: String, $backgroundImage: Upload, $parentId: ID) {categoryCreate(input: {name: $nameslug: $slugdescription: $description+ backgroundImage: $backgroundImageparent: $parentId}) {@@ -76,19 +78,23 @@ def test_category_create_mutation(category_name = 'Test category'category_slug = slugify(category_name)category_description = 'Test description'+ image_file, image_name = create_image()# test creating root categoryvariables = {'name': category_name, 'description': category_description,- 'slug': category_slug}- response = staff_api_client.post_graphql(- query, variables, permissions=[permission_manage_products])+ 'backgroundImage': image_name, 'slug': category_slug}+ body = get_multipart_request_body(query, variables, image_file, image_name)+ response = staff_api_client.post_multipart(+ body, permissions=[permission_manage_products])content = get_graphql_content(response)data = content['data']['categoryCreate']assert data['errors'] == []assert data['category']['name'] == category_nameassert data['category']['description'] == category_descriptionassert not data['category']['parent']+ category = Category.objects.get(name=category_name)+ assert category.background_image.file# test creating subcategoryparent_id = data['category']['id']@@ -105,12 +111,13 @@ def test_category_create_mutation(def test_category_update_mutation(staff_api_client, category, permission_manage_products):query = """- mutation($id: ID!, $name: String, $slug: String, $description: String) {+ mutation($id: ID!, $name: String, $slug: String, $backgroundImage: Upload, $description: String) {categoryUpdate(id: $idinput: {name: $namedescription: $description+ backgroundImage: $backgroundImageslug: $slug}) {@@ -136,13 +143,16 @@ def test_category_update_mutation(category_name = 'Updated name'category_slug = slugify(category_name)category_description = 'Updated description'+ image_file, image_name = create_image()category_id = graphene.Node.to_global_id('Category', child_category.pk)variables = {'name': category_name, 'description': category_description,- 'id': category_id, 'slug': category_slug}- response = staff_api_client.post_graphql(- query, variables, permissions=[permission_manage_products])+ 'backgroundImage': image_name, 'id': category_id,+ 'slug': category_slug}+ body = get_multipart_request_body(query, variables, image_file, image_name)+ response = staff_api_client.post_multipart(+ body, permissions=[permission_manage_products])content = get_graphql_content(response)data = content['data']['categoryUpdate']assert data['errors'] == []@@ -152,6 +162,8 @@ def test_category_update_mutation(parent_id = graphene.Node.to_global_id('Category', category.pk)assert data['category']['parent']['id'] == parent_id+ category = Category.objects.get(name=category_name)+ assert category.background_image.filedef test_category_delete_mutation(