Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Fix tests

Krzysztof Wolski57b1711ff8d1
diff --git a/tests/conftest.py b/tests/conftest.py
index e479443605..c7d73d080c 100644
--- a/tests/conftest.py
+++ b/tests/conftest.py
@@ -10,7 +10,9 @@ from saleor.cart.models import Cart
from saleor.checkout.core import Checkout
from saleor.discount.models import Voucher
from saleor.order.models import Order
-from saleor.product.models import Product, ProductVariant, Stock, StockLocation
+from saleor.product.models import (Product, ProductVariant, Stock, ProductClass,
+ AttributeChoiceValue, ProductAttribute,
+ StockLocation)
from saleor.shipping.models import ShippingMethod
from saleor.userprofile.models import Address, User
@@ -88,9 +90,35 @@ def shipping_method(db): # pylint: disable=W0613
@pytest.fixture
-def product_in_stock(db): # pylint: disable=W0613
+def color_attribute(db): # pylint: disable=W0613
+ attribute = ProductAttribute.objects.create(name='color',
+ display='Display')
+ AttributeChoiceValue.objects.create(display='Red', attribute=attribute)
+ AttributeChoiceValue.objects.create(display='Blue', attribute=attribute)
+ return attribute
+
+
+def size_attribute(db): # pylint: disable=W0613
+ attribute = ProductAttribute.objects.create(name='size', display='Size')
+ AttributeChoiceValue.objects.create(display='Small', attribute=attribute)
+ AttributeChoiceValue.objects.create(display='Big', attribute=attribute)
+ return attribute
+
+
+def product_class(db, color_attribute, size_attribute): # pylint: disable=W0613
+ product_class = ProductClass.objects.create(name='Default Class',
+ has_variants=False)
+ product_class.product_attributes.add(color_attribute)
+ product_class.variant_attributes.add(size_attribute)
+ return product_class
+
+
+def product_in_stock(db, product_class): # pylint: disable=W0613
product = Product.objects.create(
- name='Test product', price=10, weight=1)
+ name='Test product', price=10, weight=1, product_class=product_class)
variant = ProductVariant.objects.create(product=product, sku='123')
warehouse_1 = StockLocation.objects.create(name='Warehouse 1')
warehouse_2 = StockLocation.objects.create(name='Warehouse 2')
diff --git a/tests/test_discounts.py b/tests/test_discounts.py
index 4f67b8a72e..62a12375ea 100644
--- a/tests/test_discounts.py
+++ b/tests/test_discounts.py
@@ -225,12 +225,14 @@ def test_products_voucher_checkout_discount_not(settings, monkeypatch, prices,
@pytest.mark.django_db
-def test_sale_applies_to_correct_products():
+def test_sale_applies_to_correct_products(product_class):
product = Product.objects.create(
- name='Test Product', price=10, weight=1, description='', pk=10)
+ name='Test Product', price=10, weight=1, description='', pk=10,
+ product_class=product_class)
variant = ProductVariant.objects.create(product=product, sku='firstvar')
product2 = Product.objects.create(
- name='Second product', price=15, weight=1, description='')
+ name='Second product', price=15, weight=1, description='',
+ product_class=product_class)
sec_variant = ProductVariant.objects.create(
product=product2, sku='secvar', pk=10)
sale = Sale.objects.create(name='Test sale', value=5, type=Sale.FIXED)