def test_get_or_retrieve_for_api_key_djstripe_owner_account_does_not_exist(
        self, account, request, platform_account_fixture, configure_settings
    ):
        """Ensure that djstripe_owner_account is returned correctly when it doesn't already exist on the api_key."""

        # second entry is the model instance
        account = request.getfixturevalue(account)[1]
        api_key_instance = APIKey.objects.get(secret=settings.STRIPE_TEST_SECRET_KEY)
        api_key_instance.djstripe_owner_account = None
        api_key_instance.save()

        with patch(
            "djstripe.models.api.APIKey.objects.get_or_create_by_api_key",
            return_value=(api_key_instance, False),
        ):
            new_account = Account.get_or_retrieve_for_api_key(
                settings.STRIPE_TEST_SECRET_KEY
            )

        assert (
            platform_account_fixture[1].djstripe_owner_account
            == new_account.djstripe_owner_account
        )
Ensure that djstripe_owner_account is returned correctly when it doesn't already exist on the api_key.
tests/test_account.py