Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add test for Specific products type in voucher
fowczarek5825409f2147
diff --git a/tests/conftest.py b/tests/conftest.pyindex c35022baf4..16b9e179ea 100644--- a/tests/conftest.py+++ b/tests/conftest.py@@ -23,7 +23,7 @@ from saleor.checkout.models import Checkoutfrom saleor.checkout.utils import add_variant_to_checkoutfrom saleor.core.utils.taxes import DEFAULT_TAX_RATE_NAMEfrom saleor.dashboard.menu.utils import update_menu-from saleor.discount import DiscountValueType, DiscountInfo, VoucherType+from saleor.discount import DiscountInfo, DiscountValueType, VoucherTypefrom saleor.discount.models import Sale, Voucher, VoucherTranslationfrom saleor.giftcard.models import GiftCardfrom saleor.menu.models import Menu, MenuItem@@ -651,6 +651,13 @@ def voucher(db): # pylint: disable=W0613return Voucher.objects.create(code="mirumee", discount_value=20)+def voucher_specific_product_type(db):+ return Voucher.objects.create(+ code="mirumee", discount_value=10, type=VoucherType.SPECIFIC_PRODUCT+ )++@pytest.fixturedef voucher_percentage(db):return Voucher.objects.create(diff --git a/tests/test_cart.py b/tests/test_cart.pyindex 4db2862a40..14fe34819e 100644--- a/tests/test_cart.py+++ b/tests/test_cart.py@@ -21,6 +21,7 @@ from saleor.checkout.views import clear_checkout, update_checkout_linefrom saleor.core.exceptions import InsufficientStockfrom saleor.core.utils.taxes import ZERO_TAXED_MONEYfrom saleor.discount.models import Sale+from saleor.product.models import Categoryfrom saleor.shipping.utils import get_shipping_price_estimate@@ -315,6 +316,95 @@ def test_get_prices_of_discounted_products(checkout_with_item):assert list(prices) == excepted_value+def test_get_prices_of_discounted_specific_product(+ checkout_with_item, collection, voucher_specific_product_type+):+ checkout = checkout_with_item+ voucher = voucher_specific_product_type+ line = checkout.lines.first()+ product = line.variant.product+ category = product.category++ product.collections.add(collection)+ voucher.products.add(product)+ voucher.collections.add(collection)+ voucher.categories.add(category)++ prices = utils.get_prices_of_discounted_specific_product(checkout, voucher)++ excepted_value = [line.variant.get_price() for item in range(line.quantity)]++ assert prices == excepted_value+++def test_get_prices_of_discounted_specific_product_only_product(+ checkout_with_item, voucher_specific_product_type, product_with_default_variant+):+ checkout = checkout_with_item+ voucher = voucher_specific_product_type+ line = checkout.lines.first()+ product = line.variant.product+ product2 = product_with_default_variant++ add_variant_to_checkout(checkout, product2.variants.get(), 1)+ voucher.products.add(product)++ prices = utils.get_prices_of_discounted_specific_product(checkout, voucher)++ excepted_value = [line.variant.get_price() for item in range(line.quantity)]++ assert checkout.lines.count() > 1+ assert prices == excepted_value+++def test_get_prices_of_discounted_specific_product_only_collection(+ checkout_with_item,+ collection,+ voucher_specific_product_type,+ product_with_default_variant,+):+ checkout = checkout_with_item+ voucher = voucher_specific_product_type+ line = checkout.lines.first()+ product = line.variant.product+ product2 = product_with_default_variant++ add_variant_to_checkout(checkout, product2.variants.get(), 1)+ product.collections.add(collection)+ voucher.collections.add(collection)++ prices = utils.get_prices_of_discounted_specific_product(checkout, voucher)++ excepted_value = [line.variant.get_price() for item in range(line.quantity)]++ assert checkout.lines.count() > 1+ assert prices == excepted_value+++def test_get_prices_of_discounted_specific_product_only_category(+ checkout_with_item, voucher_specific_product_type, product_with_default_variant+):+ checkout = checkout_with_item+ voucher = voucher_specific_product_type+ line = checkout.lines.first()+ product = line.variant.product+ product2 = product_with_default_variant+ category = product.category+ category2 = Category.objects.create(name="Cat", slug="cat")++ product2.category = category2+ product2.save()+ add_variant_to_checkout(checkout, product2.variants.get(), 1)+ voucher.categories.add(category)++ prices = utils.get_prices_of_discounted_specific_product(checkout, voucher)++ excepted_value = [line.variant.get_price() for item in range(line.quantity)]++ assert checkout.lines.count() > 1+ assert prices == excepted_value++def test_contains_unavailable_variants():missing_variant = Mock(check_quantity=Mock(side_effect=InsufficientStock("")))checkout = MagicMock()