def test_handle_event_payment_succeeded(self, invoice_retrieve_mock, sync_invoice_mock): fake_event = Event(kind="invoice.payment_succeeded", validated_message={"data": {"object": {"id": "lock"}}}) invoice_webhook_handler(fake_event, fake_event.message["data"], "invoice", "payment_failed") invoice_retrieve_mock.assert_called_once_with("lock") sync_invoice_mock.assert_called_once_with("key", send_receipt=True)
def test_handle_event_fake(self, invoice_retrieve_mock, sync_invoice_mock): fake_event = Event(kind="fake", message={"data": { "object": { "id": "door" } }}) Invoice.handle_event(fake_event) self.assertFalse(invoice_retrieve_mock.called) self.assertFalse(sync_invoice_mock.called)
def test_handle_event_payment_failed(self, invoice_retrieve_mock, sync_invoice_mock): fake_event = Event( kind="invoice.payment_failed", validated_message={"data": { "object": { "id": "door" } }}) Invoice.handle_event(fake_event) invoice_retrieve_mock.assert_called_once_with("door") sync_invoice_mock.assert_called_once_with("lock", send_receipt=True)
def _create_stripe_event(user): return Event( data={ "object": { "id": "cus_TEST", "object": "customer", "account_balance": 0, "currency": None, "delinquent": False, "email": EmailAddress.objects.filter(user=user).first().email, "metadata": { "djstripe_customer": user.id } } })