From 92a94d2fdcb06950681cf3619cce805eceb2e9ce Mon Sep 17 00:00:00 2001 From: Bart Schuurmans Date: Fri, 29 Mar 2024 21:38:48 +0100 Subject: [PATCH] django.utils.timezone.utc alias is deprecated --- .../tests/activitystreams/test_abstractstream.py | 3 +-- bookwyrm/tests/activitystreams/test_signals.py | 8 ++++---- bookwyrm/tests/models/test_import_model.py | 2 +- bookwyrm/tests/templatetags/test_status_display.py | 14 +++++++++----- bookwyrm/tests/test_book_search.py | 3 ++- bookwyrm/tests/test_partial_date.py | 2 +- bookwyrm/tests/views/imports/test_import.py | 4 ++-- bookwyrm/tests/views/test_annual_summary.py | 4 ++-- bookwyrm/tests/views/test_readthrough.py | 3 +-- 9 files changed, 23 insertions(+), 20 deletions(-) diff --git a/bookwyrm/tests/activitystreams/test_abstractstream.py b/bookwyrm/tests/activitystreams/test_abstractstream.py index 3a95e2efa..addbd00f7 100644 --- a/bookwyrm/tests/activitystreams/test_abstractstream.py +++ b/bookwyrm/tests/activitystreams/test_abstractstream.py @@ -1,8 +1,7 @@ """ testing activitystreams """ -from datetime import datetime +from datetime import datetime, timezone from unittest.mock import patch from django.test import TestCase -from django.utils import timezone from bookwyrm import activitystreams, models diff --git a/bookwyrm/tests/activitystreams/test_signals.py b/bookwyrm/tests/activitystreams/test_signals.py index 77ac68e71..42bf26289 100644 --- a/bookwyrm/tests/activitystreams/test_signals.py +++ b/bookwyrm/tests/activitystreams/test_signals.py @@ -1,5 +1,5 @@ """ testing activitystreams """ -from datetime import datetime, timedelta +import datetime from unittest.mock import patch from django.test import TestCase @@ -71,8 +71,8 @@ class ActivitystreamsSignals(TestCase): user=self.remote_user, content="hi", privacy="public", - created_date=datetime(2022, 5, 16, tzinfo=timezone.utc), - published_date=datetime(2022, 5, 14, tzinfo=timezone.utc), + created_date=datetime.datetime(2022, 5, 16, tzinfo=datetime.timezone.utc), + published_date=datetime.datetime(2022, 5, 14, tzinfo=datetime.timezone.utc), ) with patch("bookwyrm.activitystreams.add_status_task.apply_async") as mock: activitystreams.add_status_on_create_command(models.Status, status, False) @@ -87,7 +87,7 @@ class ActivitystreamsSignals(TestCase): user=self.remote_user, content="hi", privacy="public", - published_date=timezone.now() - timedelta(days=1), + published_date=timezone.now() - datetime.timedelta(days=1), ) with patch("bookwyrm.activitystreams.add_status_task.apply_async") as mock: activitystreams.add_status_on_create_command(models.Status, status, False) diff --git a/bookwyrm/tests/models/test_import_model.py b/bookwyrm/tests/models/test_import_model.py index e591c33e8..5445a79db 100644 --- a/bookwyrm/tests/models/test_import_model.py +++ b/bookwyrm/tests/models/test_import_model.py @@ -1,10 +1,10 @@ """ testing models """ import datetime +from datetime import timezone import json import pathlib from unittest.mock import patch -from django.utils import timezone from django.test import TestCase import responses diff --git a/bookwyrm/tests/templatetags/test_status_display.py b/bookwyrm/tests/templatetags/test_status_display.py index 762f14ea8..338c30481 100644 --- a/bookwyrm/tests/templatetags/test_status_display.py +++ b/bookwyrm/tests/templatetags/test_status_display.py @@ -1,5 +1,5 @@ """ style fixes and lookups for templates """ -from datetime import datetime +import datetime from unittest.mock import patch from django.test import TestCase @@ -95,14 +95,18 @@ class StatusDisplayTags(TestCase): def test_get_published_date(self, *_): """date formatting""" - date = datetime(2020, 1, 1, 0, 0, tzinfo=timezone.utc) + date = datetime.datetime(2020, 1, 1, 0, 0, tzinfo=datetime.timezone.utc) with patch("django.utils.timezone.now") as timezone_mock: - timezone_mock.return_value = datetime(2022, 1, 1, 0, 0, tzinfo=timezone.utc) + timezone_mock.return_value = datetime.datetime( + 2022, 1, 1, 0, 0, tzinfo=datetime.timezone.utc + ) result = status_display.get_published_date(date) self.assertEqual(result, "Jan. 1, 2020") - date = datetime(2022, 1, 1, 0, 0, tzinfo=timezone.utc) + date = datetime.datetime(2022, 1, 1, 0, 0, tzinfo=datetime.timezone.utc) with patch("django.utils.timezone.now") as timezone_mock: - timezone_mock.return_value = datetime(2022, 1, 8, 0, 0, tzinfo=timezone.utc) + timezone_mock.return_value = datetime.datetime( + 2022, 1, 8, 0, 0, tzinfo=datetime.timezone.utc + ) result = status_display.get_published_date(date) self.assertEqual(result, "Jan 1") diff --git a/bookwyrm/tests/test_book_search.py b/bookwyrm/tests/test_book_search.py index 3673b9579..cc9a00154 100644 --- a/bookwyrm/tests/test_book_search.py +++ b/bookwyrm/tests/test_book_search.py @@ -1,8 +1,9 @@ """ test searching for books """ import datetime +from datetime import timezone + from django.db import connection from django.test import TestCase -from django.utils import timezone from bookwyrm import book_search, models from bookwyrm.connectors.abstract_connector import AbstractMinimalConnector diff --git a/bookwyrm/tests/test_partial_date.py b/bookwyrm/tests/test_partial_date.py index 364d00933..12d8c768d 100644 --- a/bookwyrm/tests/test_partial_date.py +++ b/bookwyrm/tests/test_partial_date.py @@ -1,10 +1,10 @@ """ test partial_date module """ import datetime +from datetime import timezone import unittest from django.core.exceptions import ValidationError -from django.utils import timezone from django.utils import translation from bookwyrm.utils import partial_date diff --git a/bookwyrm/tests/views/imports/test_import.py b/bookwyrm/tests/views/imports/test_import.py index f694b7bf5..763fcc19f 100644 --- a/bookwyrm/tests/views/imports/test_import.py +++ b/bookwyrm/tests/views/imports/test_import.py @@ -123,8 +123,8 @@ class ImportViews(TestCase): """Give people a sense of the timing""" models.ImportJob.objects.create( user=self.local_user, - created_date=datetime.datetime(2000, 1, 1), - updated_date=datetime.datetime(2001, 1, 1), + created_date=datetime.datetime(2000, 1, 1, tzinfo=datetime.timezone.utc), + updated_date=datetime.datetime(2001, 1, 1, tzinfo=datetime.timezone.utc), status="complete", complete=True, mappings={}, diff --git a/bookwyrm/tests/views/test_annual_summary.py b/bookwyrm/tests/views/test_annual_summary.py index db8389fc6..f5bd60085 100644 --- a/bookwyrm/tests/views/test_annual_summary.py +++ b/bookwyrm/tests/views/test_annual_summary.py @@ -1,5 +1,5 @@ """testing the annual summary page""" -from datetime import datetime +import datetime from unittest.mock import patch import pytz @@ -15,7 +15,7 @@ from bookwyrm.tests.validate_html import validate_html def make_date(*args): """helper function to easily generate a date obj""" - return datetime(*args, tzinfo=pytz.UTC) + return datetime.datetime(*args, tzinfo=pytz.UTC) class AnnualSummary(TestCase): diff --git a/bookwyrm/tests/views/test_readthrough.py b/bookwyrm/tests/views/test_readthrough.py index c71ee6c58..e85d4e6a4 100644 --- a/bookwyrm/tests/views/test_readthrough.py +++ b/bookwyrm/tests/views/test_readthrough.py @@ -1,8 +1,7 @@ """ tests updating reading progress """ -from datetime import datetime +from datetime import datetime, timezone from unittest.mock import patch from django.test import TestCase, Client -from django.utils import timezone from bookwyrm import models