

@patch('pinax.stripe.actions.customers.sync_customer')
@patch('stripe.Event.retrieve')
@patch('stripe.Customer.retrieve')
def test_customer_subscription_deleted(self, CustomerMock, EventMock, SyncMock):
    "\n        Tests to make sure downstream signal handlers do not see stale Subscription object properties\n        after a customer.subscription.deleted event occurs.  While the delete method is called\n        on the affected Subscription object's properties are still accessible (unless the\n        Customer object for the event gets refreshed before sending the complimentary signal)\n        "
    ev = EventMock()
    cm = CustomerMock()
    cm.currency = 'usd'
    cm.delinquent = False
    cm.default_source = ''
    cm.account_balance = 0
    kind = 'customer.subscription.deleted'
    plan = Plan.objects.create(stripe_id='p1', amount=10, currency='usd', interval='monthly', interval_count=1, name='Pro')
    cs = Subscription(stripe_id='su_2ZDdGxJ3EQQc7Q', customer=self.customer, quantity=1, start=timezone.now(), plan=plan)
    cs.save()
    customer = Customer.objects.get(pk=self.customer.pk)
    del customer.stripe_customer.subscription
    self.assertIsNotNone(customer.subscription_set.all()[0])
    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',
    }
    ev.to_dict.return_value = msg
    test_event = Event.objects.create(stripe_id=msg['id'], kind=kind, livemode=msg['livemode'], webhook_message=self, validated_message=msg, valid=True, customer=customer)
    registry.get(test_event.kind)(test_event).process()
    self.assertTrue(SyncMock.called)

dataset/ETHPy150Open pinax/pinax-stripe/pinax/stripe/tests/test_event.py TestEventMethods.test_customer_subscription_deleted/VarMisuse@403/805 `msg`->`self`