Skip to content
This repository has been archived by the owner on Sep 3, 2024. It is now read-only.

Commit

Permalink
Fix subscription update for empty/false-like values
Browse files Browse the repository at this point in the history
  • Loading branch information
lskillen committed Jul 7, 2016
1 parent 5cc9472 commit b0b9e2e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion djstripe/stripe_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -1481,7 +1481,7 @@ def update(self, plan=None, application_fee_percent=None, coupon=None, prorate=N
stripe_subscription = self.api_retrieve()

for kwarg, value in kwargs.items():
if value:
if value is not None:
setattr(stripe_subscription, kwarg, value)

return stripe_subscription.save()
Expand Down
16 changes: 16 additions & 0 deletions tests/test_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

import calendar
from copy import deepcopy
from decimal import Decimal

from django.contrib.auth import get_user_model
from django.test import TestCase
Expand Down Expand Up @@ -145,6 +146,21 @@ def test_update(self, customer_retrieve_mock, subscription_retrieve_mock, plan_r

self.assertEqual(4, new_subscription.quantity)

@patch("stripe.Plan.retrieve", return_value=deepcopy(FAKE_PLAN))
@patch("stripe.Subscription.retrieve")
@patch("stripe.Customer.retrieve", return_value=deepcopy(FAKE_CUSTOMER))
def test_update_set_empty_value(self, customer_retrieve_mock, subscription_retrieve_mock, plan_retrieve_mock):
subscription_fake = deepcopy(FAKE_SUBSCRIPTION)
subscription_fake.update({'tax_percent': Decimal(20.0)})
subscription_retrieve_mock.return_value = subscription_fake
subscription = Subscription.sync_from_stripe_data(subscription_fake)

self.assertEqual(Decimal(20.0), subscription.tax_percent)

new_subscription = subscription.update(tax_percent=Decimal(0.0))

self.assertEqual(Decimal(0.0), new_subscription.tax_percent)

@patch("stripe.Plan.retrieve", return_value=deepcopy(FAKE_PLAN))
@patch("stripe.Subscription.retrieve", return_value=deepcopy(FAKE_SUBSCRIPTION))
@patch("stripe.Customer.retrieve", return_value=deepcopy(FAKE_CUSTOMER))
Expand Down

0 comments on commit b0b9e2e

Please sign in to comment.