Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
More tests for products and orders
Krzysztof Wolski9b93f77a4f1e
diff --git a/saleor/core/utils/random_data.py b/saleor/core/utils/random_data.pyindex 4df45ab27b..25b8102ef8 100644--- a/saleor/core/utils/random_data.py+++ b/saleor/core/utils/random_data.py@@ -193,8 +193,8 @@ def create_products_by_class(product_class, schema,product, product_class.name, len(variant_combinations) or 1))-def create_products_by_schema(placeholder_dir, how_many, create_images, stdout,- schema=DEFAULT_SCHEMA):+def create_products_by_schema(placeholder_dir, how_many, create_images,+ stdout=None, schema=DEFAULT_SCHEMA):for product_class, class_schema in create_product_classes_by_schema(schema):create_products_by_class(product_class, class_schema, placeholder_dir,@@ -386,7 +386,7 @@ def create_order_lines(delivery_group, how_many=10):def create_fake_order():user = random.choice([None, User.objects.filter(- is_superuser=False).order_by('?')[0]])+ is_superuser=False).order_by('?').first()])if user:user_data = {'user': user,diff --git a/tests/test_core.py b/tests/test_core.pyindex 41e93e81d1..fed0513b2a 100644--- a/tests/test_core.py+++ b/tests/test_core.py@@ -1,14 +1,33 @@import pytestfrom mock import Mock-from saleor.core.utils import (- Country, get_country_by_ip, get_currency_for_country, create_superuser)-from saleor.core.utils.random_data import (create_shipping_methods,- create_fake_user, create_users,- create_address, create_attribute,- create_product_classes_by_schema)+from saleor.core.utils import (Country, create_superuser, get_country_by_ip,+ get_currency_for_country)+from saleor.core.utils.random_data import (create_address, create_attribute,+ create_fake_user,+ create_product_classes_by_schema,+ create_products_by_class,+ create_shipping_methods,+ create_users,+ create_orders,+ create_products_by_schema)+from saleor.order.models import Order+from saleor.product.models import Productfrom saleor.shipping.models import ShippingMethod-from saleor.userprofile.models import User, Address+from saleor.userprofile.models import Address, User+++class_schema = {'Vegetable': {+ 'category': 'Food',+ 'product_attributes': {+ 'Sweetness': ['Sweet', 'Sour'],+ 'Healthiness': ['Healthy', 'Not really']+ },+ 'variant_attributes': {+ 'GMO': ['Yes', 'No']+ },+ 'images_dir': 'candy/',+ 'is_shipping_required': True}}@pytest.mark.parametrize('ip_data, expected_country', [@@ -89,20 +108,29 @@ def test_create_attribute(db):def test_create_product_classes_by_schema(db):- schema = {'T-Shirt': {- 'category': 'Food',- 'product_attributes': {- 'Sweetness': ['Sweet', 'Sour'],- 'Healthiness': ['Healthy', 'Not really']- },- 'variant_attributes': {- 'GMO': ['Yes', 'No']- },- 'images_dir': 'candy/',- 'is_shipping_required': True}}- p_class = create_product_classes_by_schema(schema)[0][0]- assert p_class.name == 'T-Shirt'+ p_class = create_product_classes_by_schema(class_schema)[0][0]+ assert p_class.name == 'Vegetable'assert p_class.product_attributes.count() == 2assert p_class.variant_attributes.count() == 1assert p_class.is_shipping_required++def test_create_products_by_class(db):+ assert Product.objects.all().count() == 0+ how_many = 5+ p_class = create_product_classes_by_schema(class_schema)[0][0]+ create_products_by_class(p_class, class_schema['Vegetable'], '/',+ how_many=how_many, create_images=False)+ assert Product.objects.all().count() == how_many+++def test_create_fake_order(db):+ for _ in create_shipping_methods():+ pass+ for _ in create_users(3):+ pass+ create_products_by_schema('/', 10, False)+ how_many = 5+ for _ in create_orders(how_many):+ pass+ Order.objects.all().count() == 5