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 3c8e074
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
5 changes: 3 additions & 2 deletions project/tests/test_filters.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import calendar
import random
from datetime import datetime, timedelta
from datetime.timezone import utc
from itertools import groupby
from math import floor

Expand Down Expand Up @@ -147,7 +148,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 = timezone.make_aware(new_dt, utc)
self.assertFilter(new_dt, f)


Expand Down Expand Up @@ -176,7 +177,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 = timezone.make_aware(new_dt, utc)
self.assertFilter(new_dt, f)


Expand Down
13 changes: 7 additions & 6 deletions project/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import datetime
from datetime.timezone import utc
import uuid

from django.core.management import call_command
Expand Down Expand Up @@ -45,7 +46,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=utc))

def test_total_meta_time_if_have_no_meta_and_queries_time(self):

Expand Down Expand Up @@ -185,7 +186,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=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 +263,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=utc)
self.start_time = datetime.datetime(2016, 1, 1, 12, 0, 0, tzinfo=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=utc))

def test_is_m2o_related_to_request(self):

Expand Down Expand Up @@ -432,7 +433,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=utc)
obj = SQLQueryFactory.create(end_time=self.end_time)

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

0 comments on commit 3c8e074

Please sign in to comment.