Skip to content

Commit

Permalink
Merge branch 'master' into issue-290
Browse files Browse the repository at this point in the history
  • Loading branch information
paltman authored Dec 21, 2016
2 parents ede4af4 + b5205bf commit 5eec34f
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
2 changes: 1 addition & 1 deletion pinax/stripe/management/commands/sync_customers.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def handle(self, *args, **options):
count += 1
perc = int(round(100 * (float(count) / float(total))))
username = getattr(user, user.USERNAME_FIELD)
print("[{0}/{1} {2}%] Syncing {3} [{4}]".format(
print(u"[{0}/{1} {2}%] Syncing {3} [{4}]".format(
count, total, perc, username, user.pk
))
customer = customers.get_customer_for_user(user)
Expand Down
7 changes: 6 additions & 1 deletion pinax/stripe/middleware.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import django
from django.shortcuts import redirect

try:
Expand All @@ -12,7 +13,11 @@
class ActiveSubscriptionMiddleware(object):

def process_request(self, request):
if request.user.is_authenticated() and not request.user.is_staff:
is_authenticated = request.user.is_authenticated
if django.VERSION < (1, 10):
is_authenticated = is_authenticated()

if is_authenticated and not request.user.is_staff:
url_name = resolve(request.path).url_name
if url_name not in settings.PINAX_STRIPE_SUBSCRIPTION_REQUIRED_EXCEPTION_URLS:
customer = customers.get_customer_for_user(request.user)
Expand Down
12 changes: 12 additions & 0 deletions pinax/stripe/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,15 @@ def test_sync_customers_with_test_customer(self, SyncChargesMock, SyncInvoicesMo
self.assertEqual(SyncChargesMock.call_count, 0)
self.assertEqual(SyncInvoicesMock.call_count, 0)
self.assertEqual(SyncMock.call_count, 2)

@patch("stripe.Customer.retrieve")
@patch("pinax.stripe.actions.customers.sync_customer")
@patch("pinax.stripe.actions.invoices.sync_invoices_for_customer")
@patch("pinax.stripe.actions.charges.sync_charges_for_customer")
def test_sync_customers_with_unicode_username(self, SyncChargesMock, SyncInvoicesMock, SyncMock, RetrieveMock):
user2 = get_user_model().objects.create_user(username=u"tom\xe1s")
Customer.objects.create(stripe_id="cus_YYYYY", user=user2)
management.call_command("sync_customers")
self.assertEqual(SyncChargesMock.call_count, 1)
self.assertEqual(SyncInvoicesMock.call_count, 1)
self.assertEqual(SyncMock.call_count, 1)

0 comments on commit 5eec34f

Please sign in to comment.