Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

admin: customer_user: handle customer without user #417

Merged
merged 2 commits into from
Oct 25, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions pinax/stripe/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,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
@@ -1,7 +1,7 @@
import datetime

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 @@ -137,3 +137,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()), "")