Skip to content

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

Update test_checkout tests - use freezegun

IKarbowiakc90a754da4e5
diff --git a/.isort.cfg b/.isort.cfg
index d4e80f6709..43fbd9a126 100644
--- a/.isort.cfg
+++ b/.isort.cfg
@@ -1,2 +1,2 @@
[settings]
-known_third_party = PIL,babel,bleach,braintree,celery,dj_database_url,dj_email_url,django,django_countries,django_filters,django_measurement,django_prices,django_prices_openexchangerates,django_prices_vatlayer,draftjs_sanitizer,faker,freezegun,geolite2,google_measurement_protocol,graphene,graphene_django,graphene_django_optimizer,graphene_federation,graphql,graphql_jwt,graphql_relay,html5lib,html_to_draftjs,i18naddress,jwt,markdown,measurement,mptt,oauthlib,phonenumber_field,phonenumbers,prices,promise,pytest,razorpay,requests,sentry_sdk,six,storages,stripe,templated_email,text_unidecode,tqdm,versatileimagefield
+known_third_party = PIL,babel,bleach,braintree,celery,dj_database_url,dj_email_url,django,django_countries,django_filters,django_measurement,django_prices,django_prices_openexchangerates,django_prices_vatlayer,draftjs_sanitizer,faker,freezegun,geolite2,google_measurement_protocol,graphene,graphene_django,graphene_django_optimizer,graphene_federation,graphql,graphql_jwt,graphql_relay,html5lib,html_to_draftjs,i18naddress,jwt,markdown,measurement,mptt,oauthlib,phonenumber_field,phonenumbers,prices,promise,pytest,pytz,razorpay,requests,sentry_sdk,six,storages,stripe,templated_email,text_unidecode,tqdm,versatileimagefield
diff --git a/tests/test_checkout.py b/tests/test_checkout.py
index 513df23725..027fcd1a05 100644
--- a/tests/test_checkout.py
+++ b/tests/test_checkout.py
@@ -2,9 +2,11 @@ import datetime
from unittest.mock import Mock, patch
import pytest
+import pytz
from django.contrib.auth.models import AnonymousUser
from django.utils import timezone
from django_countries.fields import Country
+from freezegun import freeze_time
from prices import Money, TaxedMoney
from saleor.account import CustomerEvents
@@ -63,21 +65,23 @@ def test_clear_shipping_method(checkout, shipping_method):
def test_last_change_update(checkout):
- last_change = checkout.last_change
+ with freeze_time(datetime.datetime.now()) as frozen_datetime:
+ assert checkout.last_change != frozen_datetime()
- checkout.note = "Sample note"
- checkout.save()
+ checkout.note = "Sample note"
+ checkout.save()
- assert checkout.last_change != last_change
+ assert checkout.last_change == pytz.utc.localize(frozen_datetime())
def test_last_change_update_foregin_key(checkout, shipping_method):
- last_change = checkout.last_change
+ with freeze_time(datetime.datetime.now()) as frozen_datetime:
+ assert checkout.last_change != frozen_datetime()
- checkout.shipping_method = shipping_method
- checkout.save(update_fields=["shipping_method", "last_change"])
+ checkout.shipping_method = shipping_method
+ checkout.save(update_fields=["shipping_method", "last_change"])
- assert checkout.last_change != last_change
+ assert checkout.last_change == pytz.utc.localize(frozen_datetime())
@pytest.mark.parametrize("is_anonymous_user", (True, False))