def test_category_update_mutation(staff_api_client, category, permission_manage_products): query = """ mutation($id: ID!, $name: String, $slug: String, $backgroundImage: Upload, $description: String) { categoryUpdate( id: $id input: { name: $name description: $description backgroundImage: $backgroundImage slug: $slug } ) { category { id name description parent { id } } errors { field message } } } """ # create child category and test that the update mutation won't change # it's parent child_category = category.children.create(name='child') 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, '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'] == [] assert data['category']['id'] == category_id assert data['category']['name'] == category_name assert data['category']['description'] == category_description 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.file
def test_category_update_mutation( monkeypatch, staff_api_client, category, permission_manage_products, media_root ): mock_create_thumbnails = Mock(return_value=None) monkeypatch.setattr( ( "saleor.product.thumbnails." "create_category_background_image_thumbnails.delay" ), mock_create_thumbnails, ) # create child category and test that the update mutation won't change # it's parent child_category = category.children.create(name="child") category_name = "Updated name" category_slug = slugify(category_name) category_description = "Updated description" image_file, image_name = create_image() image_alt = "Alt text for an image." category_id = graphene.Node.to_global_id("Category", child_category.pk) variables = { "name": category_name, "description": category_description, "backgroundImage": image_name, "backgroundImageAlt": image_alt, "id": category_id, "slug": category_slug, } body = get_multipart_request_body( MUTATION_CATEGORY_UPDATE_MUTATION, 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"] == [] assert data["category"]["id"] == category_id assert data["category"]["name"] == category_name assert data["category"]["description"] == category_description 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.file mock_create_thumbnails.assert_called_once_with(category.pk) assert data["category"]["backgroundImage"]["alt"] == image_alt
def test_category_update_mutation( monkeypatch, staff_api_client, category, permission_manage_products, media_root ): mock_create_thumbnails = Mock(return_value=None) monkeypatch.setattr( ( "saleor.dashboard.category.forms." "create_category_background_image_thumbnails.delay" ), mock_create_thumbnails, ) # create child category and test that the update mutation won't change # it's parent child_category = category.children.create(name="child") category_name = "Updated name" category_slug = slugify(category_name) category_description = "Updated description" image_file, image_name = create_image() image_alt = "Alt text for an image." category_id = graphene.Node.to_global_id("Category", child_category.pk) variables = { "name": category_name, "description": category_description, "backgroundImage": image_name, "backgroundImageAlt": image_alt, "id": category_id, "slug": category_slug, } body = get_multipart_request_body( MUTATION_CATEGORY_UPDATE_MUTATION, 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"] == [] assert data["category"]["id"] == category_id assert data["category"]["name"] == category_name assert data["category"]["description"] == category_description 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.file mock_create_thumbnails.assert_called_once_with(category.pk) assert data["category"]["backgroundImage"]["alt"] == image_alt
def test_category_update_mutation(monkeypatch, staff_api_client, category, permission_manage_products): mock_create_thumbnails = Mock(return_value=None) monkeypatch.setattr(('saleor.dashboard.category.forms.' 'create_category_background_image_thumbnails.delay'), mock_create_thumbnails) # create child category and test that the update mutation won't change # it's parent child_category = category.children.create(name='child') category_name = 'Updated name' category_slug = slugify(category_name) category_description = 'Updated description' image_file, image_name = create_image() image_alt = 'Alt text for an image.' category_id = graphene.Node.to_global_id('Category', child_category.pk) variables = { 'name': category_name, 'description': category_description, 'backgroundImage': image_name, 'backgroundImageAlt': image_alt, 'id': category_id, 'slug': category_slug } body = get_multipart_request_body(MUTATION_CATEGORY_UPDATE_MUTATION, 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'] == [] assert data['category']['id'] == category_id assert data['category']['name'] == category_name assert data['category']['description'] == category_description 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.file mock_create_thumbnails.assert_called_once_with(category.pk) assert data['category']['backgroundImage']['alt'] == image_alt
def test_category_update_mutation_invalid_background_image( staff_api_client, category, permission_manage_products): image_file, image_name = create_pdf_file_with_image_ext() image_alt = 'Alt text for an image.' variables = { 'name': 'new-name', 'slug': 'new-slug', 'id': to_global_id('Category', category.id), 'backgroundImage': image_name, 'backgroundImageAlt': image_alt, 'isPublished': True } body = get_multipart_request_body(MUTATION_CATEGORY_UPDATE_MUTATION, 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'][0]['field'] == 'backgroundImage' assert data['errors'][0]['message'] == 'Invalid file type'
def test_category_update_mutation_invalid_background_image( staff_api_client, category, permission_manage_products): image_file, image_name = create_pdf_file_with_image_ext() image_alt = "Alt text for an image." variables = { "name": "new-name", "slug": "new-slug", "id": to_global_id("Category", category.id), "backgroundImage": image_name, "backgroundImageAlt": image_alt, "isPublished": True, } body = get_multipart_request_body(MUTATION_CATEGORY_UPDATE_MUTATION, 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"][0]["field"] == "backgroundImage" assert data["errors"][0]["message"] == "Invalid file type"
def test_category_update_mutation_invalid_background_image( staff_api_client, category, permission_manage_products): image_file, image_name = create_pdf_file_with_image_ext() image_alt = 'Alt text for an image.' variables = { 'name': 'new-name', 'slug': 'new-slug', 'id': to_global_id('Category', category.id), 'backgroundImage': image_name, 'backgroundImageAlt': image_alt, 'isPublished': True} body = get_multipart_request_body( MUTATION_CATEGORY_UPDATE_MUTATION, 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'][0]['field'] == 'backgroundImage' assert data['errors'][0]['message'] == 'Invalid file type'
def test_category_update_mutation( monkeypatch, staff_api_client, category, permission_manage_products): mock_create_thumbnails = Mock(return_value=None) monkeypatch.setattr( ('saleor.dashboard.category.forms.' 'create_category_background_image_thumbnails.delay'), mock_create_thumbnails) # create child category and test that the update mutation won't change # it's parent child_category = category.children.create(name='child') category_name = 'Updated name' category_slug = slugify(category_name) category_description = 'Updated description' image_file, image_name = create_image() image_alt = 'Alt text for an image.' category_id = graphene.Node.to_global_id('Category', child_category.pk) variables = { 'name': category_name, 'description': category_description, 'backgroundImage': image_name, 'backgroundImageAlt': image_alt, 'id': category_id, 'slug': category_slug} body = get_multipart_request_body( MUTATION_CATEGORY_UPDATE_MUTATION, 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'] == [] assert data['category']['id'] == category_id assert data['category']['name'] == category_name assert data['category']['description'] == category_description 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.file mock_create_thumbnails.assert_called_once_with(category.pk) assert data['category']['backgroundImage']['alt'] == image_alt
def test_category_update_mutation_invalid_background_image( staff_api_client, category, permission_manage_products ): image_file, image_name = create_pdf_file_with_image_ext() image_alt = "Alt text for an image." variables = { "name": "new-name", "slug": "new-slug", "id": to_global_id("Category", category.id), "backgroundImage": image_name, "backgroundImageAlt": image_alt, "isPublished": True, } body = get_multipart_request_body( MUTATION_CATEGORY_UPDATE_MUTATION, 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"][0]["field"] == "backgroundImage" assert data["errors"][0]["message"] == "Invalid file type"
def test_category_create_mutation(monkeypatch, staff_api_client, permission_manage_products): query = """ mutation( $name: String, $slug: String, $description: String, $descriptionJson: JSONString, $backgroundImage: Upload, $backgroundImageAlt: String, $parentId: ID) { categoryCreate( input: { name: $name slug: $slug description: $description descriptionJson: $descriptionJson backgroundImage: $backgroundImage backgroundImageAlt: $backgroundImageAlt }, parent: $parentId ) { category { id name slug description descriptionJson parent { name id } backgroundImage{ alt } } errors { field message } } } """ mock_create_thumbnails = Mock(return_value=None) monkeypatch.setattr(('saleor.dashboard.category.forms.' 'create_category_background_image_thumbnails.delay'), mock_create_thumbnails) category_name = 'Test category' category_slug = slugify(category_name) category_description = 'Test description' category_description_json = json.dumps({'content': 'description'}) image_file, image_name = create_image() image_alt = 'Alt text for an image.' # test creating root category variables = { 'name': category_name, 'description': category_description, 'descriptionJson': category_description_json, 'backgroundImage': image_name, 'backgroundImageAlt': image_alt, '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_name assert data['category']['description'] == category_description assert data['category']['descriptionJson'] == category_description_json assert not data['category']['parent'] category = Category.objects.get(name=category_name) assert category.background_image.file mock_create_thumbnails.assert_called_once_with(category.pk) assert data['category']['backgroundImage']['alt'] == image_alt # test creating subcategory parent_id = data['category']['id'] variables = { 'name': category_name, 'description': category_description, 'parentId': parent_id, 'slug': category_slug } response = staff_api_client.post_graphql(query, variables) content = get_graphql_content(response) data = content['data']['categoryCreate'] assert data['errors'] == [] assert data['category']['parent']['id'] == parent_id
def test_category_create_mutation(monkeypatch, staff_api_client, permission_manage_products, media_root): query = """ mutation( $name: String, $slug: String, $description: String, $descriptionJson: JSONString, $backgroundImage: Upload, $backgroundImageAlt: String, $parentId: ID) { categoryCreate( input: { name: $name slug: $slug description: $description descriptionJson: $descriptionJson backgroundImage: $backgroundImage backgroundImageAlt: $backgroundImageAlt }, parent: $parentId ) { category { id name slug description descriptionJson parent { name id } backgroundImage{ alt } } errors { field message } } } """ mock_create_thumbnails = Mock(return_value=None) monkeypatch.setattr( ("saleor.dashboard.category.forms." "create_category_background_image_thumbnails.delay"), mock_create_thumbnails, ) category_name = "Test category" category_slug = slugify(category_name) category_description = "Test description" category_description_json = json.dumps({"content": "description"}) image_file, image_name = create_image() image_alt = "Alt text for an image." # test creating root category variables = { "name": category_name, "description": category_description, "descriptionJson": category_description_json, "backgroundImage": image_name, "backgroundImageAlt": image_alt, "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_name assert data["category"]["description"] == category_description assert data["category"]["descriptionJson"] == category_description_json assert not data["category"]["parent"] category = Category.objects.get(name=category_name) assert category.background_image.file mock_create_thumbnails.assert_called_once_with(category.pk) assert data["category"]["backgroundImage"]["alt"] == image_alt # test creating subcategory parent_id = data["category"]["id"] variables = { "name": category_name, "description": category_description, "parentId": parent_id, "slug": category_slug, } response = staff_api_client.post_graphql(query, variables) content = get_graphql_content(response) data = content["data"]["categoryCreate"] assert data["errors"] == [] assert data["category"]["parent"]["id"] == parent_id
def test_category_create_mutation( monkeypatch, staff_api_client, permission_manage_products, media_root ): query = """ mutation( $name: String, $slug: String, $description: String, $descriptionJson: JSONString, $backgroundImage: Upload, $backgroundImageAlt: String, $parentId: ID) { categoryCreate( input: { name: $name slug: $slug description: $description descriptionJson: $descriptionJson backgroundImage: $backgroundImage backgroundImageAlt: $backgroundImageAlt }, parent: $parentId ) { category { id name slug description descriptionJson parent { name id } backgroundImage{ alt } } errors { field message } } } """ mock_create_thumbnails = Mock(return_value=None) monkeypatch.setattr( ( "saleor.dashboard.category.forms." "create_category_background_image_thumbnails.delay" ), mock_create_thumbnails, ) category_name = "Test category" category_slug = slugify(category_name) category_description = "Test description" category_description_json = json.dumps({"content": "description"}) image_file, image_name = create_image() image_alt = "Alt text for an image." # test creating root category variables = { "name": category_name, "description": category_description, "descriptionJson": category_description_json, "backgroundImage": image_name, "backgroundImageAlt": image_alt, "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_name assert data["category"]["description"] == category_description assert data["category"]["descriptionJson"] == category_description_json assert not data["category"]["parent"] category = Category.objects.get(name=category_name) assert category.background_image.file mock_create_thumbnails.assert_called_once_with(category.pk) assert data["category"]["backgroundImage"]["alt"] == image_alt # test creating subcategory parent_id = data["category"]["id"] variables = { "name": category_name, "description": category_description, "parentId": parent_id, "slug": category_slug, } response = staff_api_client.post_graphql(query, variables) content = get_graphql_content(response) data = content["data"]["categoryCreate"] assert data["errors"] == [] assert data["category"]["parent"]["id"] == parent_id
def test_category_create_mutation(staff_api_client, permission_manage_products): query = """ mutation($name: String, $slug: String, $description: String, $backgroundImage: Upload, $parentId: ID) { categoryCreate( input: { name: $name slug: $slug description: $description backgroundImage: $backgroundImage }, parent: $parentId ) { category { id name slug description parent { name id } } errors { field message } } } """ category_name = 'Test category' category_slug = slugify(category_name) category_description = 'Test description' image_file, image_name = create_image() # test creating root category variables = { 'name': category_name, 'description': category_description, '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_name assert data['category']['description'] == category_description assert not data['category']['parent'] category = Category.objects.get(name=category_name) assert category.background_image.file # test creating subcategory parent_id = data['category']['id'] variables = { 'name': category_name, 'description': category_description, 'parentId': parent_id, 'slug': category_slug } response = staff_api_client.post_graphql(query, variables) content = get_graphql_content(response) data = content['data']['categoryCreate'] assert data['errors'] == [] assert data['category']['parent']['id'] == parent_id
def test_category_create_mutation( monkeypatch, staff_api_client, permission_manage_products): query = """ mutation( $name: String, $slug: String, $description: String, $descriptionJson: JSONString, $backgroundImage: Upload, $backgroundImageAlt: String, $parentId: ID) { categoryCreate( input: { name: $name slug: $slug description: $description descriptionJson: $descriptionJson backgroundImage: $backgroundImage backgroundImageAlt: $backgroundImageAlt }, parent: $parentId ) { category { id name slug description descriptionJson parent { name id } backgroundImage{ alt } } errors { field message } } } """ mock_create_thumbnails = Mock(return_value=None) monkeypatch.setattr( ('saleor.dashboard.category.forms.' 'create_category_background_image_thumbnails.delay'), mock_create_thumbnails) category_name = 'Test category' category_slug = slugify(category_name) category_description = 'Test description' category_description_json = json.dumps({'content': 'description'}) image_file, image_name = create_image() image_alt = 'Alt text for an image.' # test creating root category variables = { 'name': category_name, 'description': category_description, 'descriptionJson': category_description_json, 'backgroundImage': image_name, 'backgroundImageAlt': image_alt, '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_name assert data['category']['description'] == category_description assert data['category']['descriptionJson'] == category_description_json assert not data['category']['parent'] category = Category.objects.get(name=category_name) assert category.background_image.file mock_create_thumbnails.assert_called_once_with(category.pk) assert data['category']['backgroundImage']['alt'] == image_alt # test creating subcategory parent_id = data['category']['id'] variables = { 'name': category_name, 'description': category_description, 'parentId': parent_id, 'slug': category_slug} response = staff_api_client.post_graphql(query, variables) content = get_graphql_content(response) data = content['data']['categoryCreate'] assert data['errors'] == [] assert data['category']['parent']['id'] == parent_id