def test_value_voucher_checkout_discount_not_applicable(settings): voucher = Voucher(code='unique', type=Voucher.VALUE_TYPE, discount_value_type=Voucher.DISCOUNT_VALUE_FIXED, discount_value=10, limit=100) checkout = Mock(get_subtotal=Mock(return_value=Price(10, currency='USD'))) with pytest.raises(NotApplicable) as e: voucher.get_discount_for_checkout(checkout) assert str(e.value) == 'This offer is only valid for orders over $100.00.'
def test_value_voucher_checkout_discount_not_applicable(settings): voucher = Voucher(code='unique', type=VoucherType.VALUE, discount_value_type=DiscountValueType.FIXED, discount_value=10, limit=100) checkout = Mock(get_subtotal=Mock(return_value=Price(10, currency='USD'))) with pytest.raises(NotApplicable) as e: voucher.get_discount_for_checkout(checkout) assert e.value.limit == Price(100, currency='USD')
def test_value_voucher_checkout_discount_not_applicable(settings): voucher = Voucher( code='unique', type=Voucher.VALUE_TYPE, discount_value_type=Voucher.DISCOUNT_VALUE_FIXED, discount_value=10, limit=100) checkout = Mock(get_subtotal=Mock( return_value=Price(10, currency='USD'))) with pytest.raises(NotApplicable) as e: voucher.get_discount_for_checkout(checkout) assert str(e.value) == 'This offer is only valid for orders over $100.00.'
def test_category_voucher_checkout_discount_not_applicable( settings, monkeypatch): monkeypatch.setattr( 'saleor.discount.models.get_category_variants_and_prices', lambda cart, product: []) voucher = Voucher(code='unique', type=VoucherType.CATEGORY, discount_value_type=DiscountValueType.FIXED, discount_value=10) checkout = Mock(cart=Mock()) with pytest.raises(NotApplicable) as e: voucher.get_discount_for_checkout(checkout) assert str(e.value) == 'This offer is only valid for selected items.'
def test_category_voucher_checkout_discount_not_applicable(settings, monkeypatch): monkeypatch.setattr( 'saleor.discount.models.get_category_variants_and_prices', lambda cart, product: []) voucher = Voucher( code='unique', type=Voucher.CATEGORY_TYPE, discount_value_type=Voucher.DISCOUNT_VALUE_FIXED, discount_value=10) checkout = Mock(cart=Mock()) with pytest.raises(NotApplicable) as e: voucher.get_discount_for_checkout(checkout) assert str(e.value) == 'This offer is only valid for selected items.'
def test_product_voucher_checkout_discount_not_applicable(settings, monkeypatch): monkeypatch.setattr( 'saleor.discount.models.get_product_variants_and_prices', lambda cart, product: []) settings.DEFAULT_CURRENCY = 'USD' voucher = Voucher( code='unique', type=Voucher.PRODUCT_TYPE, discount_value_type=Voucher.DISCOUNT_VALUE_FIXED, discount_value=10) checkout = Mock(cart=Mock()) with pytest.raises(NotApplicable) as e: voucher.get_discount_for_checkout(checkout) assert str(e.value) == 'This offer is only valid for selected items.'
def test_shipping_voucher_checkout_discountnot_applicable( settings, is_shipping_required, shipping_method, discount_value, discount_type, apply_to, limit, subtotal, error_msg): checkout = Mock(is_shipping_required=is_shipping_required, shipping_method=shipping_method, get_subtotal=Mock(return_value=subtotal)) voucher = Voucher( code='unique', type=Voucher.SHIPPING_TYPE, discount_value_type=discount_type, discount_value=discount_value, limit=Price(limit, currency='USD') if limit is not None else None, apply_to=apply_to) with pytest.raises(NotApplicable) as e: voucher.get_discount_for_checkout(checkout) assert str(e.value) == error_msg
def test_shipping_voucher_checkout_discountnot_applicable( settings, is_shipping_required, shipping_method, discount_value, discount_type, apply_to, limit, error_msg): settings.DEFAULT_CURRENCY = 'USD' checkout = Mock(is_shipping_required=is_shipping_required, shipping_method=shipping_method) voucher = Voucher( code='unique', type=Voucher.SHIPPING_TYPE, discount_value_type=discount_type, discount_value=discount_value, limit=Price(limit, currency='USD') if limit is not None else None, apply_to=apply_to) with pytest.raises(NotApplicable) as e: voucher.get_discount_for_checkout(checkout) assert str(e.value) == error_msg
def test_value_voucher_checkout_discount(settings, total, discount_value, discount_type, limit, expected_value): voucher = Voucher( code='unique', type=Voucher.VALUE_TYPE, discount_value_type=discount_type, discount_value=discount_value, limit=Price(limit, currency='USD') if limit is not None else None) checkout = Mock(get_subtotal=Mock(return_value=Price(total, currency='USD'))) discount = voucher.get_discount_for_checkout(checkout) assert discount.amount == Price(expected_value, currency='USD')
def test_value_voucher_checkout_discount(settings, total, discount_value, discount_type, limit, expected_value): voucher = Voucher( code='unique', type=Voucher.VALUE_TYPE, discount_value_type=discount_type, discount_value=discount_value, limit=Price(limit, currency='USD') if limit is not None else None) checkout = Mock(get_subtotal=Mock(return_value=Price(total, currency='USD'))) discount = voucher.get_discount_for_checkout(checkout) assert discount.amount == Price(expected_value, currency='USD')
def test_products_voucher_checkout_discount_not(settings, monkeypatch, prices, discount_value, discount_type, apply_to, expected_value): monkeypatch.setattr( 'saleor.discount.models.get_product_variants_and_prices', lambda cart, product: ( (None, Price(p, currency='USD')) for p in prices)) voucher = Voucher(code='unique', type=VoucherType.PRODUCT, discount_value_type=discount_type, discount_value=discount_value, apply_to=apply_to) checkout = Mock(cart=Mock()) discount = voucher.get_discount_for_checkout(checkout) assert discount.amount == Price(expected_value, currency='USD')
def test_shipping_voucher_checkout_discount( settings, shipping_cost, shipping_country_code, discount_value, discount_type, apply_to, expected_value): settings.DEFAULT_CURRENCY = 'USD' checkout = Mock( is_shipping_required=True, shipping_method=Mock( price=Price(shipping_cost, currency='USD'), country_code=shipping_country_code)) voucher = Voucher( code='unique', type=Voucher.SHIPPING_TYPE, discount_value_type=discount_type, discount_value=discount_value, apply_to=apply_to) discount = voucher.get_discount_for_checkout(checkout) assert discount.amount == Price(expected_value, currency='USD')
def test_products_voucher_checkout_discount_not(settings, monkeypatch, prices, discount_value, discount_type, apply_to, expected_value): monkeypatch.setattr( 'saleor.discount.models.get_product_variants_and_prices', lambda cart, product: ( (None, Price(p, currency='USD')) for p in prices)) voucher = Voucher( code='unique', type=Voucher.PRODUCT_TYPE, discount_value_type=discount_type, discount_value=discount_value, apply_to=apply_to) checkout = Mock(cart=Mock()) discount = voucher.get_discount_for_checkout(checkout) assert discount.amount == Price(expected_value, currency='USD')
def test_shipping_voucher_checkout_discount( settings, shipping_cost, shipping_country_code, discount_value, discount_type, apply_to, expected_value): checkout = Mock( get_subtotal=Mock(return_value=Price(100, currency='USD')), is_shipping_required=True, shipping_method=Mock( price=Price(shipping_cost, currency='USD'), country_code=shipping_country_code)) voucher = Voucher( code='unique', type=Voucher.SHIPPING_TYPE, discount_value_type=discount_type, discount_value=discount_value, apply_to=apply_to, limit=None) discount = voucher.get_discount_for_checkout(checkout) assert discount.amount == Price(expected_value, currency='USD')
def test_shipping_voucher_checkout_discount( settings, shipping_cost, shipping_country_code, discount_value, discount_type, apply_to, expected_value): checkout = Mock( get_subtotal=Mock(return_value=Price(100, currency='USD')), is_shipping_required=True, shipping_method=Mock( price=Price(shipping_cost, currency='USD'), country_code=shipping_country_code)) voucher = Voucher( code='unique', type=Voucher.SHIPPING_TYPE, discount_value_type=discount_type, discount_value=discount_value, apply_to=apply_to, limit=None) discount = voucher.get_discount_for_checkout(checkout) assert discount.amount == Price(expected_value, currency='USD')