Skip to content

Commit

Permalink
Change Customer.__str__ algorithm
Browse files Browse the repository at this point in the history
If a subscriber is set, defer to that. Otherwise, use Stripe's algorithm.
  • Loading branch information
jleclanche committed Jun 5, 2020
1 parent 426c9ea commit 86d44d9
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 18 deletions.
10 changes: 4 additions & 6 deletions djstripe/models/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -530,12 +530,10 @@ class Meta:
unique_together = ("subscriber", "livemode")

def __str__(self):
if not self.subscriber:
return "{id} (deleted)".format(id=self.id)
elif self.subscriber.email:
return self.subscriber.email
else:
return self.id
if self.subscriber:
return str(self.subscriber)

return self.name or self.description or self.id

@classmethod
def _manipulate_stripe_object_hook(cls, data):
Expand Down
8 changes: 2 additions & 6 deletions tests/test_customer.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,9 @@ def setUp(self):
self.account = default_account()

def test_str(self):
self.assertEqual(str(self.customer), self.user.email)
self.customer.subscriber.email = ""
self.assertEqual(str(self.customer), self.customer.id)
self.assertEqual(str(self.customer), str(self.user))
self.customer.subscriber = None
self.assertEqual(
str(self.customer), "{id} (deleted)".format(id=self.customer.id)
)
self.assertEqual(str(self.customer), self.customer.description)

def test_balance(self):
self.assertEqual(self.customer.balance, 0)
Expand Down
7 changes: 1 addition & 6 deletions tests/test_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,7 @@ def test_sync_from_stripe_data(
subscription_fake = deepcopy(FAKE_SUBSCRIPTION)
subscription = Subscription.sync_from_stripe_data(subscription_fake)

self.assertEqual(
str(subscription),
"{email} on {plan}".format(
email=self.user.email, plan=str(subscription.plan)
),
)
self.assertEqual(str(subscription), f"{self.user} on {subscription.plan}")

self.assertEqual(subscription.default_tax_rates.count(), 1)
self.assertEqual(
Expand Down

0 comments on commit 86d44d9

Please sign in to comment.