def test_update_collection_invalid_background_image( staff_api_client, collection, 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("Collection", collection.id), "backgroundImage": image_name, "backgroundImageAlt": image_alt, "isPublished": True, } body = get_multipart_request_body( MUTATION_UPDATE_COLLECTION_WITH_BACKGROUND_IMAGE, variables, image_file, image_name, ) response = staff_api_client.post_multipart( body, permissions=[permission_manage_products] ) content = get_graphql_content(response) data = content["data"]["collectionUpdate"] assert data["errors"][0]["field"] == "backgroundImage" assert data["errors"][0]["message"] == "Invalid file type"
def test_invalid_product_image_create_mutation(admin_api_client, product): query = """ mutation createProductImage($image: Upload!, $product: ID!) { productImageCreate(input: {image: $image, product: $product}) { image { id url sortOrder } errors { field message } } } """ image_file, image_name = create_pdf_file_with_image_ext() variables = { 'product': graphene.Node.to_global_id('Product', product.id), 'image': image_name } body = get_multipart_request_body(query, variables, image_file, image_name) response = admin_api_client.post_multipart(reverse('api'), body) content = get_graphql_content(response) assert 'errors' not in content assert content['data']['productImageCreate']['errors'] == [{ 'field': 'image', 'message': 'Invalid file type' }] product.refresh_from_db() assert product.images.count() == 0
def test_invalid_product_image_create_mutation(admin_api_client, product): query = """ mutation createProductImage($image: Upload!, $product: ID!) { productImageCreate(input: {image: $image, product: $product}) { image { id url sortOrder } errors { field message } } } """ image_file, image_name = create_pdf_file_with_image_ext() variables = { 'product': graphene.Node.to_global_id('Product', product.id), 'image': image_name} body = get_multipart_request_body(query, variables, image_file, image_name) response = admin_api_client.post_multipart(reverse('api'), body) content = get_graphql_content(response) assert 'errors' not in content assert content['data']['productImageCreate']['errors'] == [{ 'field': 'image', 'message': 'Invalid file type'}] product.refresh_from_db() assert product.images.count() == 0
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!, $id: ID!) { productImageUpdate(id: $id, input: {image: $image, alt: $alt, product: $product}) { productImage { image } errors { field message } } } """ image_obj = product_with_image.images.first() image = image_obj.image 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, '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']['productImageUpdate']['errors'] == [{ 'field': 'image', 'message': 'Invalid file type'}] product_with_image.refresh_from_db() assert product_with_image.images.count() == 1 assert product_with_image.images.first().image == image
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_update_collection_invalid_background_image( staff_api_client, collection, 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('Collection', collection.id), 'backgroundImage': image_name, 'backgroundImageAlt': image_alt, 'isPublished': True} body = get_multipart_request_body( MUTATION_UPDATE_COLLECTION_WITH_BACKGROUND_IMAGE, variables, image_file, image_name) response = staff_api_client.post_multipart( body, permissions=[permission_manage_products]) content = get_graphql_content(response) data = content['data']['collectionUpdate'] assert data['errors'][0]['field'] == 'backgroundImage' assert data['errors'][0]['message'] == 'Invalid file type'
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!, $id: ID!) { productImageUpdate(id: $id, input: {image: $image, alt: $alt, product: $product}) { productImage { image } errors { field message } } } """ image_obj = product_with_image.images.first() image = image_obj.image 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, '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']['productImageUpdate']['errors'] == [{ 'field': 'image', 'message': 'Invalid file type' }] product_with_image.refresh_from_db() assert product_with_image.images.count() == 1 assert product_with_image.images.first().image == image