Skip to content

Commit

Permalink
remove explicit references to pytz
Browse files Browse the repository at this point in the history
[#184132800]
  • Loading branch information
uraniumanchor committed Dec 6, 2023
1 parent 8526312 commit ec8f12f
Show file tree
Hide file tree
Showing 27 changed files with 147 additions and 147 deletions.
23 changes: 0 additions & 23 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,3 @@ updates:
schedule:
interval: daily
open-pull-requests-limit: 10
ignore:
- dependency-name: django
versions:
- ">= 3.a, < 4"
- dependency-name: pre-commit
versions:
- 2.11.0
- 2.12.0
- dependency-name: django-paypal
versions:
- "1.1"
- dependency-name: djangorestframework
versions:
- 3.12.3
- dependency-name: responses
versions:
- 0.13.0
- dependency-name: django-timezone-field
versions:
- 4.1.1
- dependency-name: importlib-metadata
- dependency-name: pytz
- dependency-name: tzdata
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ def get_package_name(name):
},
install_requires=[
'backports.cached-property~=1.0.2;python_version<"3.8"',
'backports.zoneinfo;python_version<"3.9"',
'celery~=5.0',
'channels>=2.0',
'Django>=3.2,!=4.0.*,<4.3',
Expand All @@ -59,8 +60,7 @@ def get_package_name(name):
'django-post-office~=3.2',
'django-timezone-field>=3.1,<7.0',
'djangorestframework~=3.9',
'python-dateutil~=2.8.1',
'pytz>=2019.3',
'python-dateutil~=2.8.1', # TODO: remove when 3.11 is oldest supported version
'requests>=2.27.1,<2.32.0',
],
python_requires='>=3.7, <3.12',
Expand Down
11 changes: 7 additions & 4 deletions tests/apiv2/test_donations.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
import random
from datetime import datetime, timedelta

import pytz
from django.contrib.admin.models import CHANGE
from django.contrib.auth.models import Permission, User
from rest_framework.test import APIClient

from tracker.api.serializers import DonationSerializer
from tracker.api.views.donations import DONATION_CHANGE_LOG_MESSAGES
from tracker.models import Donation, Event
from tracker.util import utcnow

from .. import randgen
from ..util import APITestCase
Expand All @@ -30,7 +30,7 @@ def generate_donations(
count=1,
state: str,
transactionstate='COMPLETED',
time: datetime = datetime.utcnow(),
time: datetime = None,
):
commentstate = 'PENDING'
readstate = 'PENDING'
Expand All @@ -53,6 +53,9 @@ def generate_donations(
commentstate = 'APPROVED'
readstate = 'IGNORED'

if time is None:
time = utcnow()

donations = randgen.generate_donations(
self.rand,
event,
Expand Down Expand Up @@ -112,7 +115,7 @@ def test_unprocessed_returns_only_after_timestamp(self):
'/tracker/api/v2/donations/unprocessed/',
{
'event_id': self.event.pk,
'after': datetime.utcnow().astimezone(pytz.utc),
'after': utcnow(),
},
)
returned_ids = list(map(lambda d: d['id'], response.data))
Expand Down Expand Up @@ -183,7 +186,7 @@ def test_flagged_returns_only_after_timestamp(self):
'/tracker/api/v2/donations/flagged/',
{
'event_id': self.event.pk,
'after': datetime.utcnow().astimezone(pytz.utc),
'after': utcnow(),
},
)
returned_ids = list(map(lambda d: d['id'], response.data))
Expand Down
9 changes: 4 additions & 5 deletions tests/randgen.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import os
from decimal import Decimal

import pytz

from tracker.models import (
Bid,
Donation,
Expand All @@ -21,6 +19,7 @@
SpeedRun,
)
from tracker.models.donation import DonationDomainChoices, DonorVisibilityChoices
from tracker.util import utcnow


def random_name(rand, base):
Expand Down Expand Up @@ -105,7 +104,7 @@ def random_time(rand, start, end):
result = start + datetime.timedelta(
seconds=rand.randrange(int(delta.total_seconds()))
)
return result.astimezone(pytz.utc)
return result.astimezone(datetime.timezone.utc)


def pick_random_from_queryset(rand, q):
Expand Down Expand Up @@ -414,7 +413,7 @@ def generate_donation_for_prize(
def generate_event(rand, start_time=None):
event = Event()
if not start_time:
start_time = datetime.datetime.utcnow().astimezone(pytz.utc)
start_time = utcnow()
event.datetime = start_time
event.name = random_event_name(rand)
event.short = event.name
Expand Down Expand Up @@ -649,7 +648,7 @@ def build_random_event(
event = generate_event(rand, start_time=start_time)
if not start_time:
start_time = datetime.datetime.combine(event.date, datetime.time()).replace(
tzinfo=pytz.utc
tzinfo=datetime.timezone.utc
)
event.save()

Expand Down
7 changes: 3 additions & 4 deletions tests/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,13 @@ django-mptt==0.14.0
django-post-office==3.6.0
django-timezone-field==6.1.0
djangorestframework==3.14.0
backports.zoneinfo==0.2.1 ; python_version<"3.9"
# TODO: can be removed when 3.11 is oldest supported version
python-dateutil==2.8.2
# can be removed when either 3.7 is not supported or once we upgrade Celery
importlib_metadata==4.13.0 ; python_version<"3.8"
pre-commit==3.5.0 ; python_version>="3.8"
pre-commit==2.21.0 ; python_version<"3.8"
python-dateutil==2.8.2
# lock these down until backports.zoneinfo is in use
pytz==2022.2.1
tzdata==2022.2
webpack-manifest==2.1.1
# only for testing
responses~=0.24.1
Expand Down
8 changes: 3 additions & 5 deletions tests/test_api.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import datetime
import json
from decimal import Decimal

import pytz
from django.contrib.admin.models import ADDITION as LogEntryADDITION
from django.contrib.admin.models import CHANGE as LogEntryCHANGE
from django.contrib.admin.models import DELETION as LogEntryDELETION
Expand All @@ -21,7 +21,7 @@


def format_time(dt):
return DjangoJSONEncoder().default(dt.astimezone(pytz.utc))
return DjangoJSONEncoder().default(dt.astimezone(datetime.timezone.utc))


class TestGeneric(APITestCase):
Expand Down Expand Up @@ -1022,9 +1022,7 @@ def add_event_fields(fields, event, prefix):
except TypeError:
pass
fields[prefix + '__' + key] = value
fields[prefix + '__datetime'] = DjangoJSONEncoder().default(
event.datetime.astimezone(pytz.utc)
)
fields[prefix + '__datetime'] = event.datetime
fields[prefix + '__public'] = str(event)

run_fields = {}
Expand Down
8 changes: 3 additions & 5 deletions tests/test_consumers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
from decimal import Decimal
from unittest import mock

import dateutil
import pytz
from asgiref.sync import async_to_sync, sync_to_async
from channels.testing import WebsocketCommunicator
from django.contrib.auth.models import Permission, User
Expand All @@ -15,6 +13,7 @@
from tracker.api.views.donations import DonationProcessingActionTypes
from tracker.consumers import DonationConsumer, PingConsumer
from tracker.consumers.processing import ProcessingConsumer, broadcast_processing_action
from tracker.util import utcnow

from .util import today_noon

Expand All @@ -29,9 +28,8 @@ async def test_ping_consumer(self):
self.assertTrue(connected, 'Could not connect')
await communicator.send_to(text_data='PING')
result = await communicator.receive_from()
# TODO: python 3.7 has datetime.datetime.fromisoformat
date = dateutil.parser.parse(result)
now = datetime.datetime.now(pytz.utc)
date = datetime.datetime.fromisoformat(result)
now = utcnow()
self.assertTrue(
(date - now).total_seconds() < 5,
msg=f'{date} and {now} differed by more than five seconds',
Expand Down
19 changes: 13 additions & 6 deletions tests/test_delete_protection.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import datetime

import pytz
from django.db.models import ProtectedError
from django.test import TransactionTestCase

Expand All @@ -12,7 +11,7 @@ def setUp(self):
self.event = models.Event.objects.create(
short='scratch',
name='Scratch Event',
datetime=datetime.datetime(2000, 1, 1, 12, tzinfo=pytz.utc),
datetime=datetime.datetime(2000, 1, 1, 12, tzinfo=datetime.timezone.utc),
targetamount=1000,
)

Expand Down Expand Up @@ -54,8 +53,12 @@ def scratchPrizeTimed(self):
name='Scratch Prize Timed',
event=self.event,
defaults=dict(
starttime=datetime.datetime(2000, 1, 1, 0, 0, 0, tzinfo=pytz.utc),
endtime=datetime.datetime(2000, 1, 1, 1, 0, 0, tzinfo=pytz.utc),
starttime=datetime.datetime(
2000, 1, 1, 0, 0, 0, tzinfo=datetime.timezone.utc
),
endtime=datetime.datetime(
2000, 1, 1, 1, 0, 0, tzinfo=datetime.timezone.utc
),
),
)[0]

Expand Down Expand Up @@ -107,8 +110,12 @@ def scratchRun(self):
name='Scratch Run',
event=self.event,
defaults=dict(
starttime=datetime.datetime(2000, 1, 1, 0, 0, 0, tzinfo=pytz.utc),
endtime=datetime.datetime(2000, 1, 1, 1, 0, 0, tzinfo=pytz.utc),
starttime=datetime.datetime(
2000, 1, 1, 0, 0, 0, tzinfo=datetime.timezone.utc
),
endtime=datetime.datetime(
2000, 1, 1, 1, 0, 0, tzinfo=datetime.timezone.utc
),
),
)[0]

Expand Down
11 changes: 0 additions & 11 deletions tests/test_donation.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from django.contrib.auth.models import Permission, User
from django.test import TestCase, override_settings
from django.urls import reverse
from django.utils import timezone

from tracker import models

Expand All @@ -26,7 +25,6 @@ def setUp(self):
def test_anonymous(self):
# Anonymous donation is anonymous
donation = models.Donation(
timereceived=timezone.now(),
amount=Decimal(1.5),
domain='PAYPAL',
requestedvisibility='ANON',
Expand All @@ -36,7 +34,6 @@ def test_anonymous(self):

# Donation from an anonymous donor with CURR is anonymous
donation = models.Donation(
timereceived=timezone.now(),
amount=Decimal(1.5),
domain='PAYPAL',
requestedvisibility='CURR',
Expand All @@ -47,7 +44,6 @@ def test_anonymous(self):

# Donation from a non-anonymous donor with CURR is not anonymous
donation = models.Donation(
timereceived=timezone.now(),
amount=Decimal(1.5),
domain='PAYPAL',
requestedvisibility='CURR',
Expand All @@ -62,7 +58,6 @@ def test_approve_if_anonymous_and_no_comment(self):

# If the comment was already read (or anything not pending), don't act
donation = models.Donation.objects.create(
timereceived=timezone.now(),
readstate='READ',
amount=Decimal(1.5),
domain='PAYPAL',
Expand All @@ -74,7 +69,6 @@ def test_approve_if_anonymous_and_no_comment(self):

# With no threshold given, leave as is
donation = models.Donation.objects.create(
timereceived=timezone.now(),
amount=Decimal(1.5),
domain='PAYPAL',
requestedvisibility='ANON',
Expand All @@ -88,7 +82,6 @@ def test_approve_if_anonymous_and_no_comment(self):

# With a threshold and a donation above it, send to reader
donation = models.Donation.objects.create(
timereceived=timezone.now(),
amount=Decimal(10),
domain='PAYPAL',
requestedvisibility='CURR',
Expand All @@ -99,7 +92,6 @@ def test_approve_if_anonymous_and_no_comment(self):

# With a threshold and a donation below it, ignore
donation = models.Donation.objects.create(
timereceived=timezone.now(),
amount=Decimal(1.5),
domain='PAYPAL',
requestedvisibility='ANON',
Expand All @@ -110,7 +102,6 @@ def test_approve_if_anonymous_and_no_comment(self):

# Donation with a non-anonymous donor should not bypass screening
donation = models.Donation.objects.create(
timereceived=timezone.now(),
amount=Decimal(10),
domain='PAYPAL',
requestedvisibility='ALIAS',
Expand All @@ -121,7 +112,6 @@ def test_approve_if_anonymous_and_no_comment(self):

# Donation with a comment should not bypass screening
donation = models.Donation.objects.create(
timereceived=timezone.now(),
amount=Decimal(10),
comment='Hello',
domain='PAYPAL',
Expand All @@ -137,7 +127,6 @@ def test_approve_if_anonymous_and_no_comment(self):
self.event.save()

donation = models.Donation.objects.create(
timereceived=timezone.now(),
amount=Decimal(10),
domain='PAYPAL',
requestedvisibility='CURR',
Expand Down
6 changes: 0 additions & 6 deletions tests/test_donor.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
import datetime
import logging
import random
from decimal import Decimal

import pytz
from django.contrib.auth.models import User
from django.test import TestCase
from django.urls import reverse
Expand Down Expand Up @@ -37,7 +35,6 @@ def test_donor_cache(self):
amount=5,
domain='PAYPAL',
transactionstate='COMPLETED',
timereceived=datetime.datetime.now(pytz.utc),
)
self.assertEqual(2, models.DonorCache.objects.count())
d2 = models.Donation.objects.create(
Expand All @@ -46,7 +43,6 @@ def test_donor_cache(self):
amount=5,
domain='PAYPAL',
transactionstate='COMPLETED',
timereceived=datetime.datetime.now(pytz.utc),
)
self.assertEqual(3, models.DonorCache.objects.count())
d3 = models.Donation.objects.create(
Expand All @@ -55,7 +51,6 @@ def test_donor_cache(self):
amount=10,
domain='PAYPAL',
transactionstate='COMPLETED',
timereceived=datetime.datetime.now(pytz.utc),
)
self.assertEqual(3, models.DonorCache.objects.count())
d4 = models.Donation.objects.create(
Expand All @@ -64,7 +59,6 @@ def test_donor_cache(self):
amount=20,
domain='PAYPAL',
transactionstate='COMPLETED',
timereceived=datetime.datetime.now(pytz.utc),
)
self.assertEqual(5, models.DonorCache.objects.count())
self.assertEqual(
Expand Down
Loading

0 comments on commit ec8f12f

Please sign in to comment.