From 78481809a718c07ab4f38a4569278a679e662b19 Mon Sep 17 00:00:00 2001 From: Alex Tomkins Date: Mon, 22 Sep 2025 09:52:03 +0100 Subject: [PATCH] Use time-machine for testing Newer versions of botocore have changed the imports for datetime, and using different functions. So use time-machine as a more reliable mock. --- requirements/testing.txt | 1 + tests/test_storage.py | 11 ++++------- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/requirements/testing.txt b/requirements/testing.txt index 40ee824..61d52c8 100644 --- a/requirements/testing.txt +++ b/requirements/testing.txt @@ -3,4 +3,5 @@ check-wheel-contents==0.6.1 coverage==7.8.0 pipdeptree==2.26.0 ruff==0.11.5 +time-machine==2.19.0 twine==6.1.0 diff --git a/tests/test_storage.py b/tests/test_storage.py index 9247739..c3be460 100644 --- a/tests/test_storage.py +++ b/tests/test_storage.py @@ -1,4 +1,3 @@ -import datetime import os from unittest import mock from urllib import parse @@ -6,6 +5,8 @@ from django.core.files.storage import DefaultStorage from django.test import TestCase, override_settings +import time_machine + from contentfiles.storage import MediaStorage, PrivateStorage, private_storage @@ -70,12 +71,8 @@ def test_private_storage(self, mock_get_date): CONTENTFILES_S3_REGION="eu-west-2", CONTENTFILES_S3_ENDPOINT_URL="https://s3.dualstack.eu-west-2.amazonaws.com", ) - @mock.patch("botocore.auth.datetime") - def test_private_storage_aws4(self, mock_datetime): - mock_datetime.datetime.utcnow.return_value = datetime.datetime( - 2020, 1, 1, 12, 34, 56, 0, tzinfo=datetime.timezone.utc - ) - + @time_machine.travel("20200101T123456Z") + def test_private_storage_aws4(self): storage = PrivateStorage() storage.access_key = "AKIA1234567890ABCDEF" storage.secret_key = "1234567890123456789012345678901234567890" # noqa:S105