Skip to content

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

Fix for differences between times in test_discount

Maciej Korycinski8e84462e7995
diff --git a/tests/api/test_discount.py b/tests/api/test_discount.py
index 92201c1eac..1012803fde 100644
--- a/tests/api/test_discount.py
+++ b/tests/api/test_discount.py
@@ -5,6 +5,7 @@ import graphene
import pytest
from django.utils import timezone
from django_countries import countries
+from freezegun import freeze_time
from saleor.discount import DiscountValueType, VoucherType
from saleor.discount.models import Sale, Voucher
@@ -171,6 +172,7 @@ mutation voucherCreate(
"""
+@freeze_time("2010-05-31 12:00:01")
def test_create_voucher(staff_api_client, permission_manage_discounts):
start_date = timezone.now() - timedelta(days=365)
end_date = timezone.now() + timedelta(days=365)
@@ -203,6 +205,7 @@ def test_create_voucher(staff_api_client, permission_manage_discounts):
assert voucher.usage_limit == 3
+@freeze_time("2010-05-31 12:00:01")
def test_create_voucher_with_empty_code(staff_api_client, permission_manage_discounts):
start_date = timezone.now() - timedelta(days=365)
end_date = timezone.now() + timedelta(days=365)
@@ -227,6 +230,7 @@ def test_create_voucher_with_empty_code(staff_api_client, permission_manage_disc
assert data["code"] != ""
+@freeze_time("2010-05-31 12:00:01")
def test_create_voucher_with_deprecated_type(
staff_api_client, permission_manage_discounts
):
@@ -254,6 +258,7 @@ def test_create_voucher_with_deprecated_type(
assert data["type"] == VoucherTypeEnum.ENTIRE_ORDER.name
+@freeze_time("2010-05-31 12:00:01")
def test_create_voucher_with_existing_gift_card_code(
staff_api_client, gift_card, permission_manage_discounts
):
@@ -281,6 +286,7 @@ def test_create_voucher_with_existing_gift_card_code(
assert errors[0]["field"] == "promoCode"
+@freeze_time("2010-05-31 12:00:01")
def test_create_voucher_with_existing_voucher_code(
staff_api_client, voucher_shipping_type, permission_manage_discounts
):
@@ -534,6 +540,7 @@ def test_voucher_remove_no_catalogues(
assert voucher.collections.exists()
+@freeze_time("2010-05-31 12:00:01")
def test_create_sale(staff_api_client, permission_manage_discounts):
query = """
mutation saleCreate(
@@ -774,6 +781,7 @@ def test_sale_remove_no_catalogues(
assert sale.collections.exists()
+@freeze_time("2019-05-31 12:00:01")
@pytest.mark.parametrize(
"voucher_filter, start_date, end_date, count",
[
@@ -893,7 +901,9 @@ def test_query_vouchers_with_filter_started(
name="Voucher2",
discount_value=123,
code="123",
- start_date=timezone.now().replace(year=2012, month=1, day=5),
+ start_date=timezone.now().replace(
+ year=2012, month=1, day=5, microsecond=0
+ ),
),
]
)
@@ -971,6 +981,7 @@ def test_query_vouchers_with_filter_search(
assert len(data) == count
+@freeze_time("2019-05-31 12:00:01")
@pytest.mark.parametrize(
"sale_filter, start_date, end_date, count",
[