Skip to content

Commit

Permalink
Merge pull request #417 from blueyed/fix-admin-customer_user
Browse files Browse the repository at this point in the history
admin: customer_user: handle customer without user
  • Loading branch information
paltman authored Oct 25, 2017
2 parents 477d209 + 27f644a commit 4d1c734
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 2 additions & 0 deletions pinax/stripe/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,8 @@ def customer_has_card(obj):


def customer_user(obj):
if not obj.customer.user:
return ""
User = get_user_model()
username = getattr(obj.customer.user, User.USERNAME_FIELD)
email = getattr(obj, "email", "")
Expand Down
16 changes: 15 additions & 1 deletion pinax/stripe/tests/test_admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import django
from django.contrib.auth import get_user_model
from django.test import Client, TestCase
from django.test import Client, SimpleTestCase, TestCase
from django.utils import timezone

from ..models import Customer, Invoice, Plan, Subscription
Expand Down Expand Up @@ -146,3 +146,17 @@ def test_charge_admin(self):
url = reverse("admin:pinax_stripe_charge_changelist")
response = self.client.get(url)
self.assertEqual(response.status_code, 200)


class AdminSimpleTestCase(SimpleTestCase):

def test_customer_user_without_user(self):
from ..admin import customer_user

class CustomerWithoutUser(object):
user = None

class Obj(object):
customer = CustomerWithoutUser()

self.assertEqual(customer_user(Obj()), "")

0 comments on commit 4d1c734

Please sign in to comment.