Skip to content

Commit

Permalink
Add fixes for PR dj-stripe#320 review
Browse files Browse the repository at this point in the history
  • Loading branch information
lskillen committed Jun 30, 2016
1 parent 5a2759d commit c20c3b2
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 24 deletions.
21 changes: 5 additions & 16 deletions djstripe/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,8 @@ def add_card(self, source, set_default=True):
def upcoming_invoice(self, **kwargs):
""" Gets the upcoming preview invoice (singular) for this customer.
See the documentation in ``djstripe.stripe_objects.StripeInvoice.upcoming()` for details on method parameters.
The ``customer`` parameter is set to the customer object this method is being called on.
See `StripeInvoice.upcoming() <#djstripe.stripe_objects.StripeInvoice.upcoming>`__
The ``customer`` argument to the ``upcoming()`` call is automatically set by this method.
"""

kwargs['customer'] = self
Expand Down Expand Up @@ -559,21 +559,10 @@ def _attach_objects_post_save_hook(self, cls, data):

@classmethod
def upcoming(cls, **kwargs):
""" Gets the upcoming preview invoice (singular) for a customer.
upcoming_stripe_invoice = StripeInvoice.upcoming(**kwargs)

See the documentation in ``djstripe.stripe_objects.StripeInvoice.upcoming()` for details on method parameters.
"""

if not issubclass(cls, UpcomingInvoice):
if cls is Invoice:
cls = UpcomingInvoice
else:
assert False, "Class argument needs to be derived from UpcomingInvoice"

stripe_invoice = StripeInvoice.upcoming(**kwargs)

if stripe_invoice:
return cls._create_from_stripe_object(stripe_invoice, save=False)
if upcoming_stripe_invoice:
return UpcomingInvoice._create_from_stripe_object(upcoming_stripe_invoice, save=False)

@property
def plan(self):
Expand Down
2 changes: 1 addition & 1 deletion docs/models.rst
Original file line number Diff line number Diff line change
Expand Up @@ -124,9 +124,9 @@ Invoice
.. autoattribute:: djstripe.models.Invoice.STATUS_CLOSED
.. autoattribute:: djstripe.models.Invoice.STATUS_OPEN
.. autoattribute:: djstripe.models.Invoice.status
.. autoattribute:: djstripe.models.Invoice.plan

.. automethod:: djstripe.models.Invoice.retry

.. automethod:: djstripe.models.Invoice.upcoming

.. automethod:: djstripe.models.Invoice.str_parts
Expand Down
7 changes: 0 additions & 7 deletions tests/test_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,3 @@ def test_no_upcoming_invoices(self, invoice_upcoming_mock):
def test_upcoming_invoice_error(self, invoice_upcoming_mock):
with self.assertRaises(InvalidRequestError):
Invoice.upcoming()

def test_upcoming_invoice_with_wrong_type(self):
class DerivedInvoice(Invoice):
pass

with self.assertRaises(AssertionError):
DerivedInvoice.upcoming()

0 comments on commit c20c3b2

Please sign in to comment.