From 4f63cb224382600183320002d71afcea36ab6ba7 Mon Sep 17 00:00:00 2001 From: Jerome Leclanche Date: Fri, 4 Aug 2017 18:55:59 +0300 Subject: [PATCH] Change Customer.__str__() to be a human-readable string --- djstripe/models.py | 18 +++++++----------- runtests.py | 4 ++-- tests/test_customer.py | 7 +++---- 3 files changed, 12 insertions(+), 17 deletions(-) diff --git a/djstripe/models.py b/djstripe/models.py index 3aa21c5bd5..f3dbccdf88 100644 --- a/djstripe/models.py +++ b/djstripe/models.py @@ -141,6 +141,7 @@ def human_readable(self): @class_doc_inherit +@python_2_unicode_compatible class Customer(StripeCustomer): doc = """ @@ -174,18 +175,13 @@ class Customer(StripeCustomer): class Meta: unique_together = ("subscriber", "livemode") - def str_parts(self): - parts = [] - - if self.subscriber: - parts.append(smart_text(self.subscriber)) - parts.append("email={email}".format(email=self.subscriber.email)) + def __str__(self): + if not self.subscriber: + return "{stripe_id} (deleted)".format(stripe_id=self.stripe_id) + elif self.subscriber.email: + return self.subscriber.email else: - parts.append("(deleted)") - - parts.extend(super(Customer, self).str_parts()) - - return parts + return self.stripe_id @classmethod def get_or_create(cls, subscriber, livemode=djstripe_settings.STRIPE_LIVE_MODE): diff --git a/runtests.py b/runtests.py index 8306c69b9b..1edda1ac14 100644 --- a/runtests.py +++ b/runtests.py @@ -43,9 +43,9 @@ def run_test_suite(args): "default": { "ENGINE": "django.db.backends.postgresql_psycopg2", "NAME": "djstripe", - "USER": "", + "USER": "postgres", "PASSWORD": "", - "HOST": "", + "HOST": "localhost", "PORT": "", }, }, diff --git a/tests/test_customer.py b/tests/test_customer.py index 0986038196..9bb4328d6a 100644 --- a/tests/test_customer.py +++ b/tests/test_customer.py @@ -43,9 +43,9 @@ def setUp(self): self.account = Account.objects.create() def test_str(self): - self.assertEqual("<{subscriber}, email={email}, stripe_id={stripe_id}>".format( - subscriber=str(self.user), email=self.user.email, stripe_id=FAKE_CUSTOMER["id"] - ), str(self.customer)) + self.assertEqual(str(self.customer), self.user.email) + self.customer.subscriber = None + self.assertEqual(str(self.customer), "{stripe_id} (deleted)".format(stripe_id=self.customer.stripe_id)) def test_customer_dashboard_url(self): expected_url = "https://dashboard.stripe.com/test/customers/{}".format(self.customer.stripe_id) @@ -715,7 +715,6 @@ def test_delete_subscriber_purges_customer(self, customer_retrieve_mock): self.user.delete() customer = Customer.objects.get(stripe_id=FAKE_CUSTOMER["id"]) self.assertIsNotNone(customer.date_purged) - self.assertEqual(["(deleted)", "stripe_id=cus_6lsBvm5rJ0zyHc"], customer.str_parts()) @patch("stripe.Customer.retrieve") def test_delete_subscriber_without_customer_is_noop(self, customer_retrieve_mock):