Skip to content

Commit

Permalink
more fixes (dj-stripe#162)
Browse files Browse the repository at this point in the history
  • Loading branch information
kavdev committed Apr 29, 2016
1 parent 24e34f0 commit 532958b
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 76 deletions.
16 changes: 0 additions & 16 deletions djstripe/context_processors.py

This file was deleted.

2 changes: 1 addition & 1 deletion djstripe/stripe_objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -979,7 +979,7 @@ class Meta:
destination_type = StripeCharField(stripe_name="type", max_length=14, choices=DESITNATION_TYPE_CHOICES, help_text="The type of the transfer destination.")
application_fee = StripeTextField(null=True, help_text="Might be the ID of an application fee object. The Stripe API docs don't provide any information.")
destination = StripeIdField(help_text="ID of the bank account, card, or Stripe account the transfer was sent to.")
destination_payment = StripeIdField(null=True, help_text="If the destination is a Stripe account, this will be the ID of the payment that the destination account received for the transfer.")
destination_payment = StripeIdField(stripe_required=False, help_text="If the destination is a Stripe account, this will be the ID of the payment that the destination account received for the transfer.")
failure_code = StripeCharField(null=True, max_length=23, choices=FAILURE_CODE_CHOICES, help_text="Error code explaining reason for transfer failure if available. See https://stripe.com/docs/api/python#transfer_failures.")
failure_message = StripeTextField(null=True, help_text="Message to user further explaining reason for transfer failure if available.")
source_transaction = StripeIdField(null=True, help_text="ID of the charge (or other transaction) that was used to fund the transfer. If null, the transfer was funded from the available balance.")
Expand Down
16 changes: 7 additions & 9 deletions djstripe/utils.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
# -*- coding: utf-8 -*-
import warnings
import datetime

from django.core.exceptions import ImproperlyConfigured
from django.conf import settings
from django.contrib.auth import get_user_model
from django.contrib.auth.models import AnonymousUser
from django.core.exceptions import ImproperlyConfigured
from django.utils import timezone
from django.conf import settings


ANONYMOUS_USER_ERROR_MSG = (
Expand Down Expand Up @@ -126,14 +125,13 @@ def simple_stripe_pagination_iterator(stripe_object, **kwargs):
except KeyError:
continue

stripe_object_list = stripe_object.all(limit=100, **kwargs)
stripe_object_list_response = stripe_object.all(limit=100, **kwargs)

for list_object in stripe_object_list["data"]:
for list_object in stripe_object_list_response["data"]:
yield list_object

while stripe_object_list["has_more"]:
print(stripe_object_list)
stripe_object_list = stripe_object.all(limit=100, starting_after=stripe_object_list[-1], **kwargs)
while stripe_object_list_response["has_more"]:
stripe_object_list_response = stripe_object.all(limit=100, starting_after=stripe_object_list_response["data"][-1], **kwargs)

for list_object in stripe_object_list["data"]:
for list_object in stripe_object_list_response["data"]:
yield list_object
1 change: 0 additions & 1 deletion requirements_test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ mock>=1.3.0
nose>=1.3.7
termcolor>=1.1.0
tox>=2.3.1
unittest2>=1.1.0

# Contrib packages
djangorestframework>=3.3.2
Expand Down
40 changes: 39 additions & 1 deletion runtests.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,18 @@ def run_test_suite(args):
"PORT": "",
},
},
TEMPLATES=[
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.contrib.auth.context_processors.auth',
],
},
},
],
ROOT_URLCONF="tests.test_urls",
INSTALLED_APPS=[
"django.contrib.admin",
Expand Down Expand Up @@ -169,7 +181,33 @@ def run_test_suite(args):
from django_nose import NoseTestSuiteRunner

test_runner = NoseTestSuiteRunner(verbosity=1)
failures = test_runner.run_tests(["./tests/test_webhooks.py", "./tests/test_plan.py"])
failures = test_runner.run_tests(["./tests/test_account.py",
"./tests/test_admin.py",
"./tests/test_card.py",
# "./tests/test_charge.py",
"./tests/test_context_managers.py",
"./tests/test_customer.py",
"./tests/test_decorators.py",
"./tests/test_djstripe_tags.py",
"./tests/test_email.py",
"./tests/test_event_processing_exception.py",
# "./tests/test_event.py",
"./tests/test_fields.py",
"./tests/test_invoice.py",
"./tests/test_invoiceitem.py", # Update to use fakes when the model is updated
"./tests/test_managers.py",
"./tests/test_middleware.py",
"./tests/test_mixins.py", # Going to want to add new has_active(plan) logic here maybe
"./tests/test_plan.py",
"./tests/test_settings.py",
"./tests/test_stripe_object.py",
# "./tests/test_subscriptions.py",
"./tests/test_sync.py",
# "./tests/test_transfer.py",
"./tests/test_urls.py",
"./tests/test_utils.py",
# "./tests/test_views.py",
"./tests/test_webhooks.py"])

if failures:
sys.exit(failures)
Expand Down
23 changes: 0 additions & 23 deletions tests/test_context_processors.py

This file was deleted.

11 changes: 2 additions & 9 deletions tests/test_email.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,8 @@
class EmailReceiptTest(TestCase):

def setUp(self):
self.user = get_user_model().objects.create_user(username="patrick",
email="[email protected]")
self.customer = Customer.objects.create(
subscriber=self.user,
stripe_id="cus_6lsBvm5rJ0zyHc",
card_fingerprint="dgs89-3jjf039jejda-0j2d",
card_last_4="4242",
card_kind="Visa"
)
self.user = get_user_model().objects.create_user(username="patrick", email="[email protected]")
self.customer = Customer.objects.create(subscriber=self.user, stripe_id="cus_6lsBvm5rJ0zyHc")
self.account = Account.objects.create()

@patch("djstripe.models.Account.get_default_account")
Expand Down
11 changes: 3 additions & 8 deletions tests/test_invoice.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@
from datetime import timedelta
from decimal import Decimal

from django.core.exceptions import ValidationError
from django.conf import settings
from django.core.exceptions import ValidationError
from django.test.testcases import TestCase
from django.utils import timezone

from mock import patch

from djstripe.event_handlers import invoice_webhook_handler
Expand Down Expand Up @@ -161,17 +160,13 @@ def test_sync_from_stripe_data_with_charge_no_receipt(self, charge_retrieve_mock
self.assertFalse(send_receipt_mock.called)

@patch("djstripe.models.Invoice.sync_from_stripe_data")
def test_handle_event_payment_failed(self, invoice_retrieve_mock, sync_invoice_mock):
def test_handle_event_payment_failed(self, invoice_retrieve_mock):
fake_event = Event(type="invoice.payment_failed", valid=True, webhook_message={"data": {"object": {"id": "door"}}})

invoice_webhook_handler(fake_event, fake_event.message["data"], "invoice", "payment_failed")

sync_invoice_mock.assert_called_once_with({"id": "door"}, send_receipt=True)

@patch("djstripe.models.Invoice.sync_from_stripe_data")
def test_handle_event_payment_succeeded(self, invoice_retrieve_mock, sync_invoice_mock):
def test_handle_event_payment_succeeded(self, invoice_retrieve_mock):
fake_event = Event(type="invoice.payment_succeeded", valid=True, webhook_message={"data": {"object": {"id": "lock"}}})

invoice_webhook_handler(fake_event, fake_event.message["data"], "invoice", "payment_failed")

sync_invoice_mock.assert_called_once_with({"id": "lock"}, send_receipt=True)
15 changes: 7 additions & 8 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,25 +7,23 @@
"""

from datetime import datetime, timedelta
from copy import deepcopy
from datetime import datetime, timedelta
from unittest.case import SkipTest

from django.conf import settings
from django.contrib.auth.models import AnonymousUser
from django.contrib.auth import get_user_model
from django.contrib.auth.models import AnonymousUser
from django.core.exceptions import ImproperlyConfigured
from django.test import TestCase
from django.test.utils import override_settings
from django.utils import timezone
from mock import patch

from djstripe.models import convert_tstamp, Customer, Subscription
from djstripe.utils import subscriber_has_active_subscription, get_supported_currency_choices, simple_stripe_pagination_iterator

from unittest.case import SkipTest
from mock import patch

from tests.apps.testapp.models import Organization
from tests import FAKE_SUBSCRIPTION
from tests.apps.testapp.models import Organization


class TestTimestampConversion(TestCase):
Expand Down Expand Up @@ -175,6 +173,7 @@ def test_paginator_as_list(self):

def test_paginator_as_iterator(self):
stripe_object = self.StripeTestObject()
paginator = simple_stripe_pagination_iterator(stripe_object)

for test_string in self.test_strings:
self.assertEqual(next(simple_stripe_pagination_iterator(stripe_object)), test_string)
self.assertEqual(next(paginator), test_string)

0 comments on commit 532958b

Please sign in to comment.