Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove deprecated django.utils.timezone.utc #687

Merged
merged 1 commit into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions project/tests/test_filters.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import calendar
import random
from datetime import datetime, timedelta
from datetime import datetime, timedelta, timezone
from itertools import groupby
from math import floor

from django.test import TestCase
from django.utils import timezone
from django.utils import timezone as django_timezone

from silk import models
from silk.request_filters import (
Expand Down Expand Up @@ -41,13 +41,13 @@ def test_seconds_filter(self):
requests = [mock_suite.mock_request() for _ in range(0, 10)]
n = 0
for r in requests:
r.start_time = timezone.now() - timedelta(seconds=n)
r.start_time = django_timezone.now() - timedelta(seconds=n)
r.save()
n += 1
requests = models.Request.objects.filter(SecondsFilter(5))
for r in requests:
dt = r.start_time
seconds = self._time_stamp(timezone.now()) - self._time_stamp(dt)
seconds = self._time_stamp(django_timezone.now()) - self._time_stamp(dt)
self.assertTrue(seconds < 6) # 6 to give a bit of leeway in case takes too long

def test_view_name_filter(self):
Expand Down Expand Up @@ -147,7 +147,7 @@ def test_after_date_filter_str(self):
date_filter = AfterDateFilter
f = date_filter(dt_str)
new_dt = datetime.strptime(dt_str, fmt)
new_dt = timezone.make_aware(new_dt, timezone.utc)
new_dt = django_timezone.make_aware(new_dt, timezone.utc)
self.assertFilter(new_dt, f)


Expand Down Expand Up @@ -176,7 +176,7 @@ def test_before_date_filter_str(self):
date_filter = BeforeDateFilter
f = date_filter(dt_str)
new_dt = datetime.strptime(dt_str, fmt)
new_dt = timezone.make_aware(new_dt, timezone.utc)
new_dt = django_timezone.make_aware(new_dt, timezone.utc)
self.assertFilter(new_dt, f)


Expand Down
13 changes: 6 additions & 7 deletions project/tests/test_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

from django.core.management import call_command
from django.test import TestCase, override_settings
from django.utils import timezone
from freezegun import freeze_time

from silk import models
Expand Down Expand Up @@ -45,7 +44,7 @@ def test_uuid_is_primary_key(self):
def test_start_time_field_default(self):

obj = RequestMinFactory.create()
self.assertEqual(obj.start_time, datetime.datetime(2016, 1, 1, 12, 0, 0, tzinfo=timezone.utc))
self.assertEqual(obj.start_time, datetime.datetime(2016, 1, 1, 12, 0, 0, tzinfo=datetime.timezone.utc))

def test_total_meta_time_if_have_no_meta_and_queries_time(self):

Expand Down Expand Up @@ -185,7 +184,7 @@ def test_save_if_have_no_end_time(self):
@freeze_time('2016-01-01 12:00:00')
def test_save_if_have_end_time(self):

date = datetime.datetime(2016, 1, 1, 12, 0, 3, tzinfo=timezone.utc)
date = datetime.datetime(2016, 1, 1, 12, 0, 3, tzinfo=datetime.timezone.utc)
obj = models.Request(path='/some/path/', method='get', end_time=date)
obj.save()
self.assertEqual(obj.end_time, date)
Expand Down Expand Up @@ -262,14 +261,14 @@ class SQLQueryTest(TestCase):
def setUp(self):

self.obj = SQLQueryFactory.create()
self.end_time = datetime.datetime(2016, 1, 1, 12, 0, 5, tzinfo=timezone.utc)
self.start_time = datetime.datetime(2016, 1, 1, 12, 0, 0, tzinfo=timezone.utc)
self.end_time = datetime.datetime(2016, 1, 1, 12, 0, 5, tzinfo=datetime.timezone.utc)
self.start_time = datetime.datetime(2016, 1, 1, 12, 0, 0, tzinfo=datetime.timezone.utc)

@freeze_time('2016-01-01 12:00:00')
def test_start_time_field_default(self):

obj = SQLQueryFactory.create()
self.assertEqual(obj.start_time, datetime.datetime(2016, 1, 1, 12, 0, 0, tzinfo=timezone.utc))
self.assertEqual(obj.start_time, datetime.datetime(2016, 1, 1, 12, 0, 0, tzinfo=datetime.timezone.utc))

def test_is_m2o_related_to_request(self):

Expand Down Expand Up @@ -432,7 +431,7 @@ def test_save_if_no_end_and_start_time(self):
@freeze_time('2016-01-01 12:00:00')
def test_save_if_has_end_time(self):

# datetime.datetime(2016, 1, 1, 12, 0, 5, tzinfo=timezone.utc)
# datetime.datetime(2016, 1, 1, 12, 0, 5, tzinfo=datetime.timezone.utc)
obj = SQLQueryFactory.create(end_time=self.end_time)

self.assertEqual(obj.time_taken, 5000.0)
Expand Down
Loading