Skip to content

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

Add test recreating the issue

michal75c9b5df64e9
diff --git a/tests/test_discounts.py b/tests/test_discounts.py
index 8c8819bec3..408efe6021 100644
--- a/tests/test_discounts.py
+++ b/tests/test_discounts.py
@@ -1,7 +1,7 @@
+from datetime import date, timedelta
from decimal import Decimal
-
import pytest
-from mock import Mock
+from mock import Mock, patch
from prices import FixedDiscount, FractionalDiscount, Price
from django_prices.templatetags.prices_i18n import net
@@ -201,6 +201,19 @@ def test_invalid_checkout_discount_form(monkeypatch, voucher):
assert 'voucher' in form.errors
+@patch('saleor.discount.models.date')
+def test_checkout_discount_form_active_queryset(date_mock, voucher):
+ date_mock.today.return_value = date.today() - timedelta(days=1)
+ checkout = Mock(cart=Mock())
+ voucher.end_date = date.today() + timedelta(days=1)
+ voucher.save()
+ form = CheckoutDiscountForm({'voucher': voucher.code}, checkout=checkout)
+ qs = form.fields['voucher'].queryset
+ form_qs = list(qs) if qs else []
+ vouchers = Voucher.objects.all()
+ assert not set(form_qs).issubset(vouchers)
+
+
@pytest.mark.parametrize(
'prices, discount_value, discount_type, apply_to, expected_value', [
([10], 10, Voucher.DISCOUNT_VALUE_FIXED, Voucher.APPLY_TO_ONE_PRODUCT, 10), # noqa