@patch("pinax.stripe.actions.customers.sync_customer")
    @patch("stripe.Event.retrieve")
    @patch("stripe.Customer.retrieve")
    def test_customer_subscription_deleted(self, CustomerMock, EventMock, SyncMock):
        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)

        # Stripe objects will not have this attribute so we must delete it from the mocked object
        del customer.stripe_customer.subscription
        self.assertIsNotNone(customer.subscription_set.all()[0])

        # 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"
        }
        ev.to_dict.return_value = msg

        # 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,
        )

        registry.get(test_event.kind)(test_event).process()
        self.assertTrue(SyncMock.called)
Waits until the latch is released.
dataset/ETHPy150Open pinax/pinax-stripe/pinax/stripe/tests/test_event.py/TestEventMethods.test_customer_subscription_deleted--crossover with--dataset/ETHPy150Open openstack/taskflow/taskflow/types/latch.py/Latch.wait