Skip to content

Commit

Permalink
Merge pull request pinax#387 from blueyed/raise-in-commands-sync_cust…
Browse files Browse the repository at this point in the history
…omers

commands/sync_customers.py: raise in case it is not a 404
  • Loading branch information
paltman authored Nov 6, 2017
2 parents 94e9fe5 + 39e788e commit 414b4dd
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
5 changes: 3 additions & 2 deletions pinax/stripe/management/commands/sync_customers.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,11 @@ def handle(self, *args, **options):
customer = customers.get_customer_for_user(user)
try:
customers.sync_customer(customer)
except InvalidRequestError as e:
if e.http_status == 404: # pragma: no branch
except InvalidRequestError as exc:
if exc.http_status == 404: # pragma: no branch
# This user doesn't exist (might be in test mode)
continue
raise exc

if customer.date_purged is None:
invoices.sync_invoices_for_customer(customer)
Expand Down
17 changes: 17 additions & 0 deletions pinax/stripe/migrations/0017_merge_20171106_2201.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.6 on 2017-11-06 21:01
from __future__ import unicode_literals

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('pinax_stripe', '0016_auto_20171106_1234'),
('pinax_stripe', '0014_auto_20171026_1304'),
('pinax_stripe', '0016_account_authorized'),
]

operations = [
]
9 changes: 5 additions & 4 deletions pinax/stripe/tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,10 +161,11 @@ def test_sync_customers_with_test_customer_unknown_error(self, SyncChargesMock,

SyncMock.side_effect = InvalidRequestError("Unknown error", None, http_status=500)

management.call_command("sync_customers")
self.assertEqual(SyncChargesMock.call_count, 2)
self.assertEqual(SyncInvoicesMock.call_count, 2)
self.assertEqual(SyncMock.call_count, 2)
with self.assertRaises(InvalidRequestError):
management.call_command("sync_customers")
self.assertEqual(SyncChargesMock.call_count, 0)
self.assertEqual(SyncInvoicesMock.call_count, 0)
self.assertEqual(SyncMock.call_count, 1)

@patch("stripe.Customer.retrieve")
@patch("pinax.stripe.actions.customers.sync_customer")
Expand Down

0 comments on commit 414b4dd

Please sign in to comment.