Skip to content

Commit

Permalink
deps: Upgrade django to version 5 (#582)
Browse files Browse the repository at this point in the history
  • Loading branch information
wojcikmat authored Jul 2, 2024
1 parent 29675d9 commit 4665d3f
Show file tree
Hide file tree
Showing 5 changed files with 1,073 additions and 2,032 deletions.
4 changes: 3 additions & 1 deletion packages/backend/apps/finances/serializers.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import datetime

from django.conf import settings
from django.contrib import messages
from django.utils import timezone
Expand Down Expand Up @@ -135,7 +137,7 @@ def get_price(self, obj):

class StripeTimestampField(serializers.DateTimeField):
def to_representation(self, value):
return super().to_representation(timezone.datetime.fromtimestamp(value, tz=timezone.utc))
return super().to_representation(timezone.datetime.fromtimestamp(value, tz=datetime.timezone.utc))


class SubscriptionSchedulePhaseSerializer(serializers.Serializer):
Expand Down
6 changes: 4 additions & 2 deletions packages/backend/apps/finances/services/subscriptions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import datetime

from django.utils import timezone
from djstripe import models as djstripe_models, enums as djstripe_enums

Expand Down Expand Up @@ -66,7 +68,7 @@ def get_valid_schedule_phases(schedule: djstripe_models.SubscriptionSchedule):
return [
phase
for phase in schedule.phases
if timezone.datetime.fromtimestamp(phase['end_date'], tz=timezone.utc) > timezone.now()
if timezone.datetime.fromtimestamp(phase['end_date'], tz=datetime.timezone.utc) > timezone.now()
]


Expand All @@ -89,5 +91,5 @@ def is_current_schedule_phase_trialing(schedule: djstripe_models.SubscriptionSch
if not current_phase['trial_end']:
return False

trial_end = timezone.datetime.fromtimestamp(current_phase['trial_end'], tz=timezone.utc)
trial_end = timezone.datetime.fromtimestamp(current_phase['trial_end'], tz=datetime.timezone.utc)
return trial_end > timezone.now()
13 changes: 6 additions & 7 deletions packages/backend/apps/finances/tests/factories.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import uuid

import factory
import pytz
from django.utils import timezone
from djstripe import models as djstripe_models, enums

Expand Down Expand Up @@ -230,15 +229,15 @@ def items(self, create, extracted, **kwargs):
class Params:
trialing = factory.Trait(
status=enums.SubscriptionStatus.trialing,
trial_start=datetime.datetime.now(tz=pytz.UTC),
trial_end=datetime.datetime.now(tz=pytz.UTC) + datetime.timedelta(30),
trial_start=datetime.datetime.now(tz=datetime.timezone.utc),
trial_end=datetime.datetime.now(tz=datetime.timezone.utc) + datetime.timedelta(30),
)

trial_completed = factory.Trait(
status=enums.SubscriptionStatus.trialing,
current_period_start=datetime.datetime.now(tz=pytz.UTC) - datetime.timedelta(2),
trial_start=datetime.datetime.now(tz=pytz.UTC) - datetime.timedelta(2),
trial_end=datetime.datetime.now(tz=pytz.UTC) - datetime.timedelta(1),
current_period_start=datetime.datetime.now(tz=datetime.timezone.utc) - datetime.timedelta(2),
trial_start=datetime.datetime.now(tz=datetime.timezone.utc) - datetime.timedelta(2),
trial_end=datetime.datetime.now(tz=datetime.timezone.utc) - datetime.timedelta(1),
)


Expand All @@ -256,7 +255,7 @@ class Meta:
@factory.post_generation
def phases(self, create, extracted, **kwargs):
def unix_time(dt):
epoch = datetime.datetime.utcfromtimestamp(0).replace(tzinfo=pytz.UTC)
epoch = datetime.datetime.utcfromtimestamp(0).replace(tzinfo=datetime.timezone.utc)
return int((dt - epoch).total_seconds())

if not create:
Expand Down
Loading

0 comments on commit 4665d3f

Please sign in to comment.