django.utils.timezone.utc alias is deprecated

This commit is contained in:
Bart Schuurmans 2024-03-29 21:38:48 +01:00
parent 0d621b68e0
commit 92a94d2fdc
9 changed files with 23 additions and 20 deletions

View file

@ -1,8 +1,7 @@
""" testing activitystreams """ """ testing activitystreams """
from datetime import datetime from datetime import datetime, timezone
from unittest.mock import patch from unittest.mock import patch
from django.test import TestCase from django.test import TestCase
from django.utils import timezone
from bookwyrm import activitystreams, models from bookwyrm import activitystreams, models

View file

@ -1,5 +1,5 @@
""" testing activitystreams """ """ testing activitystreams """
from datetime import datetime, timedelta import datetime
from unittest.mock import patch from unittest.mock import patch
from django.test import TestCase from django.test import TestCase
@ -71,8 +71,8 @@ class ActivitystreamsSignals(TestCase):
user=self.remote_user, user=self.remote_user,
content="hi", content="hi",
privacy="public", privacy="public",
created_date=datetime(2022, 5, 16, tzinfo=timezone.utc), created_date=datetime.datetime(2022, 5, 16, tzinfo=datetime.timezone.utc),
published_date=datetime(2022, 5, 14, tzinfo=timezone.utc), published_date=datetime.datetime(2022, 5, 14, tzinfo=datetime.timezone.utc),
) )
with patch("bookwyrm.activitystreams.add_status_task.apply_async") as mock: with patch("bookwyrm.activitystreams.add_status_task.apply_async") as mock:
activitystreams.add_status_on_create_command(models.Status, status, False) activitystreams.add_status_on_create_command(models.Status, status, False)
@ -87,7 +87,7 @@ class ActivitystreamsSignals(TestCase):
user=self.remote_user, user=self.remote_user,
content="hi", content="hi",
privacy="public", 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: with patch("bookwyrm.activitystreams.add_status_task.apply_async") as mock:
activitystreams.add_status_on_create_command(models.Status, status, False) activitystreams.add_status_on_create_command(models.Status, status, False)

View file

@ -1,10 +1,10 @@
""" testing models """ """ testing models """
import datetime import datetime
from datetime import timezone
import json import json
import pathlib import pathlib
from unittest.mock import patch from unittest.mock import patch
from django.utils import timezone
from django.test import TestCase from django.test import TestCase
import responses import responses

View file

@ -1,5 +1,5 @@
""" style fixes and lookups for templates """ """ style fixes and lookups for templates """
from datetime import datetime import datetime
from unittest.mock import patch from unittest.mock import patch
from django.test import TestCase from django.test import TestCase
@ -95,14 +95,18 @@ class StatusDisplayTags(TestCase):
def test_get_published_date(self, *_): def test_get_published_date(self, *_):
"""date formatting""" """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: 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) result = status_display.get_published_date(date)
self.assertEqual(result, "Jan. 1, 2020") 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: 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) result = status_display.get_published_date(date)
self.assertEqual(result, "Jan 1") self.assertEqual(result, "Jan 1")

View file

@ -1,8 +1,9 @@
""" test searching for books """ """ test searching for books """
import datetime import datetime
from datetime import timezone
from django.db import connection from django.db import connection
from django.test import TestCase from django.test import TestCase
from django.utils import timezone
from bookwyrm import book_search, models from bookwyrm import book_search, models
from bookwyrm.connectors.abstract_connector import AbstractMinimalConnector from bookwyrm.connectors.abstract_connector import AbstractMinimalConnector

View file

@ -1,10 +1,10 @@
""" test partial_date module """ """ test partial_date module """
import datetime import datetime
from datetime import timezone
import unittest import unittest
from django.core.exceptions import ValidationError from django.core.exceptions import ValidationError
from django.utils import timezone
from django.utils import translation from django.utils import translation
from bookwyrm.utils import partial_date from bookwyrm.utils import partial_date

View file

@ -123,8 +123,8 @@ class ImportViews(TestCase):
"""Give people a sense of the timing""" """Give people a sense of the timing"""
models.ImportJob.objects.create( models.ImportJob.objects.create(
user=self.local_user, user=self.local_user,
created_date=datetime.datetime(2000, 1, 1), created_date=datetime.datetime(2000, 1, 1, tzinfo=datetime.timezone.utc),
updated_date=datetime.datetime(2001, 1, 1), updated_date=datetime.datetime(2001, 1, 1, tzinfo=datetime.timezone.utc),
status="complete", status="complete",
complete=True, complete=True,
mappings={}, mappings={},

View file

@ -1,5 +1,5 @@
"""testing the annual summary page""" """testing the annual summary page"""
from datetime import datetime import datetime
from unittest.mock import patch from unittest.mock import patch
import pytz import pytz
@ -15,7 +15,7 @@ from bookwyrm.tests.validate_html import validate_html
def make_date(*args): def make_date(*args):
"""helper function to easily generate a date obj""" """helper function to easily generate a date obj"""
return datetime(*args, tzinfo=pytz.UTC) return datetime.datetime(*args, tzinfo=pytz.UTC)
class AnnualSummary(TestCase): class AnnualSummary(TestCase):

View file

@ -1,8 +1,7 @@
""" tests updating reading progress """ """ tests updating reading progress """
from datetime import datetime from datetime import datetime, timezone
from unittest.mock import patch from unittest.mock import patch
from django.test import TestCase, Client from django.test import TestCase, Client
from django.utils import timezone
from bookwyrm import models from bookwyrm import models