From 906d183bb0124ea75977a74959c2bda0e6a02bc0 Mon Sep 17 00:00:00 2001 From: Fred Palmer Date: Fri, 27 Sep 2013 22:18:04 -0500 Subject: [PATCH 01/11] Sorting these in alphabetical order --- payments/signals.py | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/payments/signals.py b/payments/signals.py index ddf8d7399..4123f686a 100644 --- a/payments/signals.py +++ b/payments/signals.py @@ -9,40 +9,40 @@ WEBHOOK_SIGNALS = dict([ (hook, Signal(providing_args=["event"])) for hook in [ - "account.updated", "account.application.deauthorized", - "charge.succeeded", - "charge.failed", - "charge.refunded", + "account.updated", + "charge.dispute.closed", "charge.dispute.created", "charge.dispute.updated", - "charge.dispute.closed", + "charge.failed", + "charge.refunded", + "charge.succeeded", + "coupon.created", + "coupon.deleted", + "coupon.updated", "customer.created", - "customer.updated", "customer.deleted", + "customer.discount.created", + "customer.discount.deleted", + "customer.discount.updated", "customer.subscription.created", - "customer.subscription.updated", "customer.subscription.deleted", "customer.subscription.trial_will_end", - "customer.discount.created", - "customer.discount.updated", - "customer.discount.deleted", + "customer.subscription.updated", + "customer.updated", "invoice.created", - "invoice.updated", - "invoice.payment_succeeded", "invoice.payment_failed", + "invoice.payment_succeeded", + "invoice.updated", "invoiceitem.created", - "invoiceitem.updated", "invoiceitem.deleted", + "invoiceitem.updated", + "ping", "plan.created", - "plan.updated", "plan.deleted", - "coupon.created", - "coupon.updated", - "coupon.deleted", + "plan.updated", "transfer.created", - "transfer.updated", "transfer.failed", - "ping" + "transfer.updated", ] ]) From 48b90279f50f5a85b9d68bcb684dce251f0324a9 Mon Sep 17 00:00:00 2001 From: Fred Palmer Date: Sat, 28 Sep 2013 00:06:36 -0500 Subject: [PATCH 02/11] Fixing bug where event signal handlers will still be able to access the old plan even after it has been deleted --- payments/models.py | 9 +++ payments/tests/test_event.py | 113 ++++++++++++++++++++++++++++++++++- 2 files changed, 119 insertions(+), 3 deletions(-) diff --git a/payments/models.py b/payments/models.py index 35b31e138..aede568c2 100644 --- a/payments/models.py +++ b/payments/models.py @@ -611,6 +611,15 @@ def is_valid(self): return True + def delete(self, using=None): + # Set values to None so that any lingering references will not show previous values + # (such as when an Event signal is triggered after a subscription has been deleted) + super(CurrentSubscription, self).delete(using=using) + self.plan = None + self.status = None + self.quantity = 0 + self.amount = 0 + class Invoice(models.Model): diff --git a/payments/tests/test_event.py b/payments/tests/test_event.py index b26452d79..f6059209a 100644 --- a/payments/tests/test_event.py +++ b/payments/tests/test_event.py @@ -1,13 +1,14 @@ from django.test import TestCase +from django.utils import timezone -from mock import patch +from mock import patch, Mock -from ..models import Customer, Event +from ..models import Customer, Event, CurrentSubscription +from payments.signals import WEBHOOK_SIGNALS from ..utils import get_user_model class TestEventMethods(TestCase): - def setUp(self): User = get_user_model() self.user = User.objects.create_user(username="testuser") @@ -176,3 +177,109 @@ def test_process_customer_deleted(self, CustomerMock): event.process() self.assertEquals(event.customer, self.customer) self.assertEquals(event.customer.user, None) + + @staticmethod + def send_signal(customer, kind): + event = Event(customer=customer, kind=kind) + signal = WEBHOOK_SIGNALS.get(kind) + signal.send(sender=Event, event=event) + + @staticmethod + def connect_webhook_signal(kind, func, **kwargs): + signal = WEBHOOK_SIGNALS.get(kind) + signal.connect(func, **kwargs) + + @staticmethod + def disconnect_webhook_signal(kind, func, **kwargs): + signal = WEBHOOK_SIGNALS.get(kind) + signal.disconnect(func, **kwargs) + + @patch("stripe.Customer.retrieve") + def test_customer_subscription_deleted(self, CustomerMock): + """ + """ + kind = "customer.subscription.deleted" + cs = CurrentSubscription(customer=self.customer, quantity=1, start=timezone.now(), amount=0) + cs.save() + customer = Customer.objects.get(pk=self.customer.pk) + + # Stripe objects will not have this attribute so we must delete it from the mocked object + del customer.stripe_customer.subscription + self.assertIsNotNone(customer.current_subscription) + + # This is the expected format of a customer.subscription.delete message + msg = { + "id": "evt_2eRjeAlnH1XMe8", + "created": 1380317537, + "livemode": True, + "type": kind, + "data": { + "object": { + "id": "su_2ZDdGxJ3EQQc7Q", + "plan": { + "interval": "month", + "name": "xxx", + "amount": 200, + "currency": "usd", + "id": "xxx", + "object": "plan", + "livemode": True, + "interval_count": 1, + "trial_period_days": None + }, + "object": "subscription", + "start": 1379111889, + "status": "canceled", + "customer": self.customer.stripe_id, + "cancel_at_period_end": False, + "current_period_start": 1378738246, + "current_period_end": 1381330246, + "ended_at": 1380317537, + "trial_start": None, + "trial_end": None, + "canceled_at": 1380317537, + "quantity": 1, + "application_fee_percent": None + } + }, + "object": "event", + "pending_webhooks": 1, + "request": "iar_2eRjQZmn0i3G9M" + } + + # Create a test event for the message + test_event = Event.objects.create( + stripe_id=msg["id"], + kind=kind, + livemode=msg["livemode"], + webhook_message=msg, + validated_message=msg, + valid=True, + customer=customer, + ) + + def signal_handler(sender, event, **kwargs): + # Illustrate and test what signal handlers would experience + self.assertFalse(event.customer.current_subscription.is_valid()) + self.assertIsNone(event.customer.current_subscription.plan) + self.assertIsNone(event.customer.current_subscription.status) + self.assertIsNone(event.customer.current_subscription.id) + + signal_handler_mock = Mock() + # Let's make the side effect call our real function, the mock is a proxy so we can assert it was called + signal_handler_mock.side_effect = signal_handler + TestEventMethods.connect_webhook_signal(kind, signal_handler_mock, weak=False, sender=Event) + signal_handler_mock.reset_mock() + + # Now process the event - at the end of this the signal should get sent + test_event.process() + + self.assertFalse(test_event.customer.current_subscription.is_valid()) + self.assertIsNone(test_event.customer.current_subscription.plan) + self.assertIsNone(test_event.customer.current_subscription.status) + self.assertIsNone(test_event.customer.current_subscription.id) + + # Verify our signal handler was called + self.assertTrue(signal_handler_mock.called) + + TestEventMethods.disconnect_webhook_signal(kind, signal_handler_mock, weak=False, sender=Event) From 9d58153ea7b4aa5f789c228c884bcaea1b551f69 Mon Sep 17 00:00:00 2001 From: Fred Palmer Date: Sat, 28 Sep 2013 00:19:21 -0500 Subject: [PATCH 03/11] Fixing empty docstring --- payments/tests/test_event.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/payments/tests/test_event.py b/payments/tests/test_event.py index f6059209a..644844f41 100644 --- a/payments/tests/test_event.py +++ b/payments/tests/test_event.py @@ -197,6 +197,10 @@ def disconnect_webhook_signal(kind, func, **kwargs): @patch("stripe.Customer.retrieve") def test_customer_subscription_deleted(self, CustomerMock): """ + Tests to make sure downstream signal handlers do not see stale CurrentSubscription object properties + after a customer.subscription.deleted event occurs. While the delete method is called + on the affected CurrentSubscription object's properties are still accessible (unless the + Customer object for the event gets refreshed before sending the complimentary signal) """ kind = "customer.subscription.deleted" cs = CurrentSubscription(customer=self.customer, quantity=1, start=timezone.now(), amount=0) From 2bbffa4d9a25c5c6d6a9c0400d32a0a39c555f26 Mon Sep 17 00:00:00 2001 From: Fred Palmer Date: Sat, 28 Sep 2013 00:26:24 -0500 Subject: [PATCH 04/11] Pylint lines too long fixes --- payments/models.py | 7 +++++-- payments/tests/test_event.py | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/payments/models.py b/payments/models.py index aede568c2..a90f9a511 100644 --- a/payments/models.py +++ b/payments/models.py @@ -612,8 +612,11 @@ def is_valid(self): return True def delete(self, using=None): - # Set values to None so that any lingering references will not show previous values - # (such as when an Event signal is triggered after a subscription has been deleted) + """ + Set values to None while deleting the object so that any lingering + references will not show previous values (such as when an Event + signal is triggered after a subscription has been deleted) + """ super(CurrentSubscription, self).delete(using=using) self.plan = None self.status = None diff --git a/payments/tests/test_event.py b/payments/tests/test_event.py index 644844f41..0a27a8032 100644 --- a/payments/tests/test_event.py +++ b/payments/tests/test_event.py @@ -195,7 +195,7 @@ def disconnect_webhook_signal(kind, func, **kwargs): signal.disconnect(func, **kwargs) @patch("stripe.Customer.retrieve") - def test_customer_subscription_deleted(self, CustomerMock): + def test_customer_subscription_deleted(self, CustomerMock): # pylint: disable=C0301 """ Tests to make sure downstream signal handlers do not see stale CurrentSubscription object properties after a customer.subscription.deleted event occurs. While the delete method is called From fd72ba253e7715e4116eb3ecab8b6a75f016f77d Mon Sep 17 00:00:00 2001 From: Fred Palmer Date: Sat, 28 Sep 2013 17:55:29 -0500 Subject: [PATCH 05/11] Disabling Meta class warning - not sure why this wasn't working before.: 'Old-style class defined.' --- payments/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/payments/models.py b/payments/models.py index a90f9a511..f8daf0934 100644 --- a/payments/models.py +++ b/payments/models.py @@ -44,7 +44,7 @@ class StripeObject(models.Model): stripe_id = models.CharField(max_length=255, unique=True) created_at = models.DateTimeField(default=timezone.now) - class Meta: + class Meta: # pylint: disable=C1001 abstract = True @@ -640,7 +640,7 @@ class Invoice(models.Model): charge = models.CharField(max_length=50, blank=True) created_at = models.DateTimeField(default=timezone.now) - class Meta: + class Meta: # pylint: disable=C1001 ordering = ["-date"] def retry(self): From 904a43d206d261d8b0fb548877beef8442153e7b Mon Sep 17 00:00:00 2001 From: Fred Palmer Date: Sat, 28 Sep 2013 17:56:03 -0500 Subject: [PATCH 06/11] Disabling line too long for test module --- payments/tests/test_event.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/payments/tests/test_event.py b/payments/tests/test_event.py index 0a27a8032..70460eb84 100644 --- a/payments/tests/test_event.py +++ b/payments/tests/test_event.py @@ -1,3 +1,4 @@ +# pylint: disable=C0301 from django.test import TestCase from django.utils import timezone @@ -195,7 +196,7 @@ def disconnect_webhook_signal(kind, func, **kwargs): signal.disconnect(func, **kwargs) @patch("stripe.Customer.retrieve") - def test_customer_subscription_deleted(self, CustomerMock): # pylint: disable=C0301 + def test_customer_subscription_deleted(self, CustomerMock): """ Tests to make sure downstream signal handlers do not see stale CurrentSubscription object properties after a customer.subscription.deleted event occurs. While the delete method is called From 2d3d6461987e245e294c47bb6e558d1adfe8a401 Mon Sep 17 00:00:00 2001 From: Fred Palmer Date: Sat, 28 Sep 2013 18:14:03 -0500 Subject: [PATCH 07/11] Removing deprecation warnings (coming from pylint) and also altering the Meta warning to suppress for different versions of Python being used with pylint --- payments/models.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/payments/models.py b/payments/models.py index f8daf0934..ba0b095cd 100644 --- a/payments/models.py +++ b/payments/models.py @@ -44,7 +44,7 @@ class StripeObject(models.Model): stripe_id = models.CharField(max_length=255, unique=True) created_at = models.DateTimeField(default=timezone.now) - class Meta: # pylint: disable=C1001 + class Meta: # pylint: disable-msg=E0012,C1001 abstract = True @@ -640,7 +640,7 @@ class Invoice(models.Model): charge = models.CharField(max_length=50, blank=True) created_at = models.DateTimeField(default=timezone.now) - class Meta: # pylint: disable=C1001 + class Meta: # pylint: disable-msg=E0012,C1001 ordering = ["-date"] def retry(self): @@ -678,7 +678,7 @@ def sync_from_stripe_data(cls, stripe_invoice, send_receipt=True): ) ) if not created: - # pylint: disable=C0301 + # pylint: disable-msg=C0301 invoice.attempted = stripe_invoice["attempted"] invoice.closed = stripe_invoice["closed"] invoice.paid = stripe_invoice["paid"] @@ -792,7 +792,7 @@ def calculate_refund_amount(self, amount=None): return int(amount_to_refund * 100) def refund(self, amount=None): - # pylint: disable=E1121 + # pylint: disable-msg=E1121 charge_obj = stripe.Charge.retrieve( self.stripe_id ).refund( @@ -820,7 +820,7 @@ def sync_from_stripe_data(cls, data): if data.get("description"): obj.description = data["description"] if data.get("amount_refunded"): - # pylint: disable=C0301 + # pylint: disable-msg=C0301 obj.amount_refunded = (data["amount_refunded"] / decimal.Decimal("100")) if data["refunded"]: obj.amount_refunded = (data["amount"] / decimal.Decimal("100")) From 2d361c7ed52614e865b81277567c2fb29293a463 Mon Sep 17 00:00:00 2001 From: Fred Palmer Date: Sat, 28 Sep 2013 18:20:26 -0500 Subject: [PATCH 08/11] Removing deprecation warnings for pylint --- payments/forms.py | 2 +- payments/tests/test_commands.py | 5 +++-- payments/tests/test_customer.py | 11 ++++++----- payments/tests/test_email.py | 3 ++- payments/tests/test_event.py | 2 +- payments/tests/test_middleware.py | 15 ++++++++------- payments/tests/test_views.py | 3 ++- 7 files changed, 23 insertions(+), 18 deletions(-) diff --git a/payments/forms.py b/payments/forms.py index ff997db52..bfc625a86 100644 --- a/payments/forms.py +++ b/payments/forms.py @@ -4,5 +4,5 @@ class PlanForm(forms.Form): - # pylint: disable=R0924 + # pylint: disable-msg=R0924 plan = forms.ChoiceField(choices=PLAN_CHOICES + [("", "-------")]) diff --git a/payments/tests/test_commands.py b/payments/tests/test_commands.py index 4801f181f..ec8f1f663 100644 --- a/payments/tests/test_commands.py +++ b/payments/tests/test_commands.py @@ -1,3 +1,4 @@ +# pylint: disable-msg=C0301 from django.core import management from django.test import TestCase @@ -15,7 +16,7 @@ def setUp(self): @patch("stripe.Customer.retrieve") @patch("stripe.Customer.create") - def test_init_customer_creates_customer(self, CreateMock, RetrieveMock): # pylint: disable=C0301 + def test_init_customer_creates_customer(self, CreateMock, RetrieveMock): CreateMock.return_value.id = "cus_XXXXX" management.call_command("init_customers") self.assertEquals(self.user.customer.stripe_id, "cus_XXXXX") @@ -39,7 +40,7 @@ def test_plans_create(self, CreateMock): @patch("payments.models.Customer.sync_current_subscription") @patch("payments.models.Customer.sync_invoices") @patch("payments.models.Customer.sync_charges") - def test_sync_customers(self, SyncChargeesMock, SyncInvoicesMock, SyncSubscriptionMock, SyncMock, RetrieveMock): # pylint: disable=C0301 + def test_sync_customers(self, SyncChargeesMock, SyncInvoicesMock, SyncSubscriptionMock, SyncMock, RetrieveMock): user2 = get_user_model().objects.create_user(username="thomas") get_user_model().objects.create_user(username="altman") Customer.objects.create(stripe_id="cus_XXXXX", user=self.user) diff --git a/payments/tests/test_customer.py b/payments/tests/test_customer.py index 88b20302e..6287b0cbe 100644 --- a/payments/tests/test_customer.py +++ b/payments/tests/test_customer.py @@ -1,3 +1,4 @@ +# pylint: disable-msg=C0301 import decimal from django.test import TestCase @@ -44,7 +45,7 @@ def test_customer_create_user_only(self, CreateMock, RetrieveMock): @patch("stripe.Invoice.create") @patch("stripe.Customer.retrieve") @patch("stripe.Customer.create") - def test_customer_create_user_with_plan(self, CreateMock, RetrieveMock, PayMock): # pylint: disable=C0301 + def test_customer_create_user_with_plan(self, CreateMock, RetrieveMock, PayMock): self.customer.delete() stripe_customer = CreateMock() stripe_customer.active_card = None @@ -70,11 +71,11 @@ def test_customer_create_user_with_plan(self, CreateMock, RetrieveMock, PayMock) self.assertTrue(PayMock.called) self.assertTrue(customer.current_subscription.plan, "pro") - # @@@ Need to figure out a way to tempmorarily set DEFAULT_PLAN to "entry" for this test # pylint: disable=C0301 + # @@@ Need to figure out a way to tempmorarily set DEFAULT_PLAN to "entry" for this test # @patch("stripe.Invoice.create") # @patch("stripe.Customer.retrieve") # @patch("stripe.Customer.create") - # def test_customer_create_user_with_card_default_plan(self, CreateMock, RetrieveMock, PayMock): # pylint: disable=C0301 + # def test_customer_create_user_with_card_default_plan(self, CreateMock, RetrieveMock, PayMock): # self.customer.delete() # stripe_customer = CreateMock() # stripe_customer.active_card = None @@ -101,7 +102,7 @@ def test_customer_create_user_with_plan(self, CreateMock, RetrieveMock, PayMock) # self.assertTrue(customer.current_subscription.plan, "entry") @patch("stripe.Customer.retrieve") - def test_customer_subscribe_with_specified_quantity(self, CustomerRetrieveMock): # pylint: disable=C0301 + def test_customer_subscribe_with_specified_quantity(self, CustomerRetrieveMock): customer = CustomerRetrieveMock() customer.subscription.plan.id = "entry-monthly" customer.subscription.current_period_start = 1348360173 @@ -118,7 +119,7 @@ def test_customer_subscribe_with_specified_quantity(self, CustomerRetrieveMock): self.assertEqual(kwargs["quantity"], 3) @patch("stripe.Customer.retrieve") - def test_customer_subscribe_with_callback_quantity(self, CustomerRetrieveMock): # pylint: disable=C0301 + def test_customer_subscribe_with_callback_quantity(self, CustomerRetrieveMock): customer = CustomerRetrieveMock() customer.subscription.plan.id = "entry-monthly" customer.subscription.current_period_start = 1348360173 diff --git a/payments/tests/test_email.py b/payments/tests/test_email.py index fbe49c66a..b1a22e47f 100644 --- a/payments/tests/test_email.py +++ b/payments/tests/test_email.py @@ -1,3 +1,4 @@ +# pylint: disable-msg=C0301 import decimal from django.core import mail @@ -24,7 +25,7 @@ def setUp(self): @patch("stripe.Charge.retrieve") @patch("stripe.Charge.create") - def test_email_reciept_renders_amount_properly(self, ChargeMock, RetrieveMock): # pylint: disable=C0301 + def test_email_reciept_renders_amount_properly(self, ChargeMock, RetrieveMock): ChargeMock.return_value.id = "ch_XXXXX" RetrieveMock.return_value = { "id": "ch_XXXXXX", diff --git a/payments/tests/test_event.py b/payments/tests/test_event.py index 70460eb84..ab62fbad2 100644 --- a/payments/tests/test_event.py +++ b/payments/tests/test_event.py @@ -1,4 +1,4 @@ -# pylint: disable=C0301 +# pylint: disable-msg=C0301 from django.test import TestCase from django.utils import timezone diff --git a/payments/tests/test_middleware.py b/payments/tests/test_middleware.py index f87d6ba19..6118d825c 100644 --- a/payments/tests/test_middleware.py +++ b/payments/tests/test_middleware.py @@ -1,3 +1,4 @@ +# pylint: disable-msg=C0301 import decimal from django.conf import settings @@ -35,40 +36,40 @@ def setUp(self): user = authenticate(username="patrick", password="eldarion") login(self.request, user) - def test_authed_user_with_no_customer_redirects_on_non_exempt_url(self): # pylint: disable=C0301 + def test_authed_user_with_no_customer_redirects_on_non_exempt_url(self): self.request.path = "/the/app/" response = self.middleware.process_request(self.request) self.assertEqual(response.status_code, 302) self.assertEqual( - response._headers["location"][1], # pylint: disable=W0212 + response._headers["location"][1], # pylint: disable-msg=W0212 reverse(settings.SUBSCRIPTION_REQUIRED_REDIRECT) ) - def test_authed_user_with_no_customer_passes_with_exempt_url(self): # pylint: disable=C0301 + def test_authed_user_with_no_customer_passes_with_exempt_url(self): URLS.append("/accounts/signup/") self.request.path = "/accounts/signup/" response = self.middleware.process_request(self.request) self.assertIsNone(response) - def test_authed_user_with_no_active_subscription_passes_with_exempt_url(self): # pylint: disable=C0301 + def test_authed_user_with_no_active_subscription_passes_with_exempt_url(self): Customer.objects.create(stripe_id="cus_1", user=self.request.user) URLS.append("/accounts/signup/") self.request.path = "/accounts/signup/" response = self.middleware.process_request(self.request) self.assertIsNone(response) - def test_authed_user_with_no_active_subscription_redirects_on_non_exempt_url(self): # pylint: disable=C0301 + def test_authed_user_with_no_active_subscription_redirects_on_non_exempt_url(self): Customer.objects.create(stripe_id="cus_1", user=self.request.user) URLS.append("/accounts/signup/") self.request.path = "/the/app/" response = self.middleware.process_request(self.request) self.assertEqual(response.status_code, 302) self.assertEqual( - response._headers["location"][1], # pylint: disable=W0212 + response._headers["location"][1], # pylint: disable-msg=W0212 reverse(settings.SUBSCRIPTION_REQUIRED_REDIRECT) ) - def test_authed_user_with_active_subscription_redirects_on_non_exempt_url(self): # pylint: disable=C0301 + def test_authed_user_with_active_subscription_redirects_on_non_exempt_url(self): customer = Customer.objects.create( stripe_id="cus_1", user=self.request.user diff --git a/payments/tests/test_views.py b/payments/tests/test_views.py index 6b26c279a..ae8c26f9c 100644 --- a/payments/tests/test_views.py +++ b/payments/tests/test_views.py @@ -1,3 +1,4 @@ +# pylint: disable-msg=C0301 import decimal import json @@ -167,6 +168,6 @@ def test_subscribe(self, create_cus_mock, upd_card_mock, subscribe_mock): self.assertEqual(response.status_code, 200) print dir(response) self.assertEqual( - json.loads(response.content)["location"], # pylint: disable=E1103 + json.loads(response.content)["location"], # pylint: disable-msg=E1103 reverse("payments_history") ) From 6a18f4d2b731deeb6f99ef326f117bc28eab9dc3 Mon Sep 17 00:00:00 2001 From: Fred Palmer Date: Sat, 28 Sep 2013 18:38:44 -0500 Subject: [PATCH 09/11] Whoops - replacing disable-msg with disable --- payments/admin.py | 2 +- payments/forms.py | 2 +- payments/models.py | 12 ++++++------ payments/tests/test_commands.py | 2 +- payments/tests/test_customer.py | 2 +- payments/tests/test_email.py | 2 +- payments/tests/test_event.py | 2 +- payments/tests/test_middleware.py | 6 +++--- payments/tests/test_views.py | 4 ++-- payments/utils.py | 2 +- 10 files changed, 18 insertions(+), 18 deletions(-) diff --git a/payments/admin.py b/payments/admin.py index a077a32f0..6ae8549e0 100644 --- a/payments/admin.py +++ b/payments/admin.py @@ -27,7 +27,7 @@ def user_search_fields(): try: # get_field_by_name throws FieldDoesNotExist if the field is not # present on the model - # pylint: disable-msg=W0212,E1103 + # pylint: disable=W0212,E1103 User._meta.get_field_by_name("email") fields += ["user__email"] except FieldDoesNotExist: diff --git a/payments/forms.py b/payments/forms.py index bfc625a86..ff997db52 100644 --- a/payments/forms.py +++ b/payments/forms.py @@ -4,5 +4,5 @@ class PlanForm(forms.Form): - # pylint: disable-msg=R0924 + # pylint: disable=R0924 plan = forms.ChoiceField(choices=PLAN_CHOICES + [("", "-------")]) diff --git a/payments/models.py b/payments/models.py index ba0b095cd..c07213ef3 100644 --- a/payments/models.py +++ b/payments/models.py @@ -44,7 +44,7 @@ class StripeObject(models.Model): stripe_id = models.CharField(max_length=255, unique=True) created_at = models.DateTimeField(default=timezone.now) - class Meta: # pylint: disable-msg=E0012,C1001 + class Meta: # pylint: disable=E0012,C1001 abstract = True @@ -207,7 +207,7 @@ def send_signal(self): class Transfer(StripeObject): - # pylint: disable-msg=C0301 + # pylint: disable=C0301 event = models.ForeignKey(Event, related_name="transfers") amount = models.DecimalField(decimal_places=2, max_digits=9) status = models.CharField(max_length=25) @@ -640,7 +640,7 @@ class Invoice(models.Model): charge = models.CharField(max_length=50, blank=True) created_at = models.DateTimeField(default=timezone.now) - class Meta: # pylint: disable-msg=E0012,C1001 + class Meta: # pylint: disable=E0012,C1001 ordering = ["-date"] def retry(self): @@ -678,7 +678,7 @@ def sync_from_stripe_data(cls, stripe_invoice, send_receipt=True): ) ) if not created: - # pylint: disable-msg=C0301 + # pylint: disable=C0301 invoice.attempted = stripe_invoice["attempted"] invoice.closed = stripe_invoice["closed"] invoice.paid = stripe_invoice["paid"] @@ -792,7 +792,7 @@ def calculate_refund_amount(self, amount=None): return int(amount_to_refund * 100) def refund(self, amount=None): - # pylint: disable-msg=E1121 + # pylint: disable=E1121 charge_obj = stripe.Charge.retrieve( self.stripe_id ).refund( @@ -820,7 +820,7 @@ def sync_from_stripe_data(cls, data): if data.get("description"): obj.description = data["description"] if data.get("amount_refunded"): - # pylint: disable-msg=C0301 + # pylint: disable=C0301 obj.amount_refunded = (data["amount_refunded"] / decimal.Decimal("100")) if data["refunded"]: obj.amount_refunded = (data["amount"] / decimal.Decimal("100")) diff --git a/payments/tests/test_commands.py b/payments/tests/test_commands.py index ec8f1f663..9e7078d1b 100644 --- a/payments/tests/test_commands.py +++ b/payments/tests/test_commands.py @@ -1,4 +1,4 @@ -# pylint: disable-msg=C0301 +# pylint: disable=C0301 from django.core import management from django.test import TestCase diff --git a/payments/tests/test_customer.py b/payments/tests/test_customer.py index 6287b0cbe..3da63b577 100644 --- a/payments/tests/test_customer.py +++ b/payments/tests/test_customer.py @@ -1,4 +1,4 @@ -# pylint: disable-msg=C0301 +# pylint: disable=C0301 import decimal from django.test import TestCase diff --git a/payments/tests/test_email.py b/payments/tests/test_email.py index b1a22e47f..48ca10637 100644 --- a/payments/tests/test_email.py +++ b/payments/tests/test_email.py @@ -1,4 +1,4 @@ -# pylint: disable-msg=C0301 +# pylint: disable=C0301 import decimal from django.core import mail diff --git a/payments/tests/test_event.py b/payments/tests/test_event.py index ab62fbad2..70460eb84 100644 --- a/payments/tests/test_event.py +++ b/payments/tests/test_event.py @@ -1,4 +1,4 @@ -# pylint: disable-msg=C0301 +# pylint: disable=C0301 from django.test import TestCase from django.utils import timezone diff --git a/payments/tests/test_middleware.py b/payments/tests/test_middleware.py index 6118d825c..2ffaa7f6d 100644 --- a/payments/tests/test_middleware.py +++ b/payments/tests/test_middleware.py @@ -1,4 +1,4 @@ -# pylint: disable-msg=C0301 +# pylint: disable=C0301 import decimal from django.conf import settings @@ -41,7 +41,7 @@ def test_authed_user_with_no_customer_redirects_on_non_exempt_url(self): response = self.middleware.process_request(self.request) self.assertEqual(response.status_code, 302) self.assertEqual( - response._headers["location"][1], # pylint: disable-msg=W0212 + response._headers["location"][1], # pylint: disable=W0212 reverse(settings.SUBSCRIPTION_REQUIRED_REDIRECT) ) @@ -65,7 +65,7 @@ def test_authed_user_with_no_active_subscription_redirects_on_non_exempt_url(sel response = self.middleware.process_request(self.request) self.assertEqual(response.status_code, 302) self.assertEqual( - response._headers["location"][1], # pylint: disable-msg=W0212 + response._headers["location"][1], # pylint: disable=W0212 reverse(settings.SUBSCRIPTION_REQUIRED_REDIRECT) ) diff --git a/payments/tests/test_views.py b/payments/tests/test_views.py index ae8c26f9c..97438f46a 100644 --- a/payments/tests/test_views.py +++ b/payments/tests/test_views.py @@ -1,4 +1,4 @@ -# pylint: disable-msg=C0301 +# pylint: disable=C0301 import decimal import json @@ -168,6 +168,6 @@ def test_subscribe(self, create_cus_mock, upd_card_mock, subscribe_mock): self.assertEqual(response.status_code, 200) print dir(response) self.assertEqual( - json.loads(response.content)["location"], # pylint: disable-msg=E1103 + json.loads(response.content)["location"], # pylint: disable=E1103 reverse("payments_history") ) diff --git a/payments/utils.py b/payments/utils.py index aeb13a727..0819f3864 100644 --- a/payments/utils.py +++ b/payments/utils.py @@ -23,7 +23,7 @@ def convert_tstamp(response, field_name=None): def get_user_model(): # pragma: no cover try: - # pylint: disable-msg=E0611 + # pylint: disable=E0611 from django.contrib.auth import get_user_model as django_get_user_model return django_get_user_model() except ImportError: From 289cc8cabaf24e67b4e8b9fc2c14ff6bfd27eabb Mon Sep 17 00:00:00 2001 From: Fred Palmer Date: Sat, 28 Sep 2013 18:47:13 -0500 Subject: [PATCH 10/11] See if this satisfies the test matrix - removing warnings for statement --- payments/models.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/payments/models.py b/payments/models.py index c07213ef3..3dc8f20b7 100644 --- a/payments/models.py +++ b/payments/models.py @@ -617,7 +617,7 @@ def delete(self, using=None): references will not show previous values (such as when an Event signal is triggered after a subscription has been deleted) """ - super(CurrentSubscription, self).delete(using=using) + super(CurrentSubscription, self).delete(using=using) # pylint: disable=E1002,C0301 self.plan = None self.status = None self.quantity = 0 From f3f7453472c52cd73e3357f4d94694df64ca0440 Mon Sep 17 00:00:00 2001 From: Fred Palmer Date: Sat, 28 Sep 2013 19:17:37 -0500 Subject: [PATCH 11/11] Needed to put the warning suppression on the function line instead the statement where the delete takes place --- payments/models.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/payments/models.py b/payments/models.py index 3dc8f20b7..09576acee 100644 --- a/payments/models.py +++ b/payments/models.py @@ -611,13 +611,13 @@ def is_valid(self): return True - def delete(self, using=None): + def delete(self, using=None): # pylint: disable=E1002 """ Set values to None while deleting the object so that any lingering references will not show previous values (such as when an Event signal is triggered after a subscription has been deleted) """ - super(CurrentSubscription, self).delete(using=using) # pylint: disable=E1002,C0301 + super(CurrentSubscription, self).delete(using=using) self.plan = None self.status = None self.quantity = 0