Skip to content

Commit

Permalink
Remove deprecated datetime.timezone.utc
Browse files Browse the repository at this point in the history
  • Loading branch information
albertyw committed Nov 26, 2023
1 parent 64c02f8 commit 55ab981
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
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

0 comments on commit 55ab981

Please sign in to comment.