Skip to content

Commit

Permalink
Upgrade django to version 5
Browse files Browse the repository at this point in the history
  • Loading branch information
wojcikmat committed May 29, 2024
1 parent 423afdc commit 5291774
Show file tree
Hide file tree
Showing 6 changed files with 1,074 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
1 change: 1 addition & 0 deletions packages/backend/apps/finances/tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ def test_trial_fields_in_response_when_customer_already_activated_trial(
executed = graphene_client.query(
self.ACTIVE_SUBSCRIPTION_QUERY, variable_values={"tenantId": to_global_id("TenantType", tenant.id)}
)
print(executed)

assert executed['data']['activeSubscription']['phases'][0]['trialEnd']
assert executed['data']['activeSubscription']['subscription']['trialStart']
Expand Down
Loading

0 comments on commit 5291774

Please sign in to comment.