Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add test for creating product
Adam Janike09fb3958de8
diff --git a/tests/dashboard/test_graphql.py b/tests/dashboard/test_graphql.pyindex d8052b6f63..1b9a7e7cdf 100644--- a/tests/dashboard/test_graphql.py+++ b/tests/dashboard/test_graphql.py@@ -1,5 +1,5 @@import json-from unittest.mock import patch+from unittest.mock import patch, Mockimport grapheneimport pytest@@ -258,3 +258,100 @@ def test_page_delete_mutation(admin_client, page):assert data['page']['title'] == page.titlewith pytest.raises(page._meta.model.DoesNotExist):page.refresh_from_db()+++def test_create_product(+ client, product_type, default_category, size_attribute):+ query = """+ mutation createProduct(+ $productTypeId: ID!,+ $categoryId: ID!+ $name: String!,+ $description: String!,+ $isPublished: Boolean!,+ $isFeatured: Boolean!,+ $price: Float!,+ $attributes: [ValuesInput]) {+ productCreate(+ categoryId: $categoryId,+ productTypeId: $productTypeId,+ name: $name,+ description: $description,+ isPublished: $isPublished,+ isFeatured: $isFeatured,+ price: $price,+ attributes: $attributes) {+ product {+ category{+ name+ }+ description+ isPublished+ isFeatured+ name+ price{+ amount+ }+ productType{+ name+ }+ attributes{+ name+ value+ }+ }+ errors {+ message+ field+ }+ }+ }+ """++ product_type_id = graphene.Node.to_global_id(+ 'ProductType', product_type.pk)+ category_id = graphene.Node.to_global_id(+ 'Category', default_category.pk)+ product_description = 'test description'+ product_name = 'test name'+ product_isPublished = True+ product_isFeatured = False+ product_price = 22++ # Default attribute defined in product_type fixture+ color_attr = product_type.product_attributes.get(name='Color')+ color_attr_name = color_attr.name+ color_attr_value = color_attr.values.first().name+ color_attr_slug = color_attr.values.first().slug+ # Add second attribute+ product_type.product_attributes.add(size_attribute)+ size_attr_name = product_type.product_attributes.get(name='Size').name+ non_existent_attr_value = 'The cake is a lie'++ # test creating root product+ variables = json.dumps({+ 'productTypeId': product_type_id,+ 'categoryId': category_id,+ 'name': product_name,+ 'description': product_description,+ 'isPublished': product_isPublished,+ 'isFeatured': product_isFeatured,+ 'price': product_price,+ 'attributes': [+ {'name': color_attr_name, 'value': color_attr_value},+ {'name': size_attr_name, 'value': non_existent_attr_value}]})++ response = client.post(+ reverse('dashboard:api'), {'query': query, 'variables': variables})+ content = get_graphql_content(response)+ assert 'errors' not in content+ data = content['data']['productCreate']+ assert data['errors'] == []+ assert data['product']['name'] == product_name+ assert data['product']['description'] == product_description+ assert data['product']['isFeatured'] == product_isFeatured+ assert data['product']['isPublished'] == product_isPublished+ assert data['product']['productType']['name'] == product_type.name+ assert data['product']['category']['name'] == default_category.name+ assert data['product']['attributes'][1]['value'] == None+ assert data['product']['attributes'][0]['value'] == color_attr_slug