def test_process_event_failure_rolls_back(self, invoke_webhook_handlers_mock):
        """Test that process event rolls back event creation on error"""

        class HandlerException(Exception):
            pass

        invoke_webhook_handlers_mock.side_effect = HandlerException
        real_create_from_stripe_object = Event._create_from_stripe_object

        def side_effect(*args, **kwargs):
            return real_create_from_stripe_object(*args, **kwargs)

        event_data = deepcopy(FAKE_EVENT_TRANSFER_CREATED)

        self.assertFalse(
            Event.objects.filter(id=FAKE_EVENT_TRANSFER_CREATED["id"]).exists()
        )

        with (
            self.assertRaises(HandlerException),
            patch(
                "djstripe.models.Event._create_from_stripe_object",
                side_effect=side_effect,
                autospec=True,
            ) as create_from_stripe_object_mock,
        ):
            Event.process(data=event_data)

        create_from_stripe_object_mock.assert_called_once_with(
            event_data, api_key=djstripe_settings.STRIPE_SECRET_KEY
        )
        self.assertFalse(
            Event.objects.filter(id=FAKE_EVENT_TRANSFER_CREATED["id"]).exists()
        )
Test that process event rolls back event creation on error
tests/test_event.py