当前位置: 首页>>代码示例>>Python>>正文


Python Charge._attach_objects_hook方法代码示例

本文整理汇总了Python中djstripe.models.Charge._attach_objects_hook方法的典型用法代码示例。如果您正苦于以下问题:Python Charge._attach_objects_hook方法的具体用法?Python Charge._attach_objects_hook怎么用?Python Charge._attach_objects_hook使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在djstripe.models.Charge的用法示例。


在下文中一共展示了Charge._attach_objects_hook方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test__attach_objects_hook_missing_source_data

# 需要导入模块: from djstripe.models import Charge [as 别名]
# 或者: from djstripe.models.Charge import _attach_objects_hook [as 别名]
	def test__attach_objects_hook_missing_source_data(
		self, mock_account, mock_payment_method, mock_charge_account, mock_charge_source
	):
		"""Make sure we handle the case where the source data is empty or insufficient."""
		charge = Charge(
			amount=50,
			currency="usd",
			id="ch_test",
			status=ChargeStatus.failed,
			captured=False,
			paid=False,
		)
		mock_cls = create_autospec(spec=Charge, spec_set=True)
		# Empty data dict works for this test since we only look up the source key and
		# everything else is mocked.
		mock_data = {}
		starting_source = charge.source

		charge._attach_objects_hook(cls=mock_cls, data=mock_data)

		# source shouldn't be touched
		self.assertEqual(starting_source, charge.source)
		mock_payment_method._get_or_create_source.assert_not_called()

		# try again with a source key, but no object sub key.
		mock_data = {"source": {"foo": "bar"}}

		charge._attach_objects_hook(cls=mock_cls, data=mock_data)

		# source shouldn't be touched
		self.assertEqual(starting_source, charge.source)
		mock_payment_method._get_or_create_source.assert_not_called()
开发者ID:,项目名称:,代码行数:34,代码来源:

示例2: test__attach_objects_hook_no_destination_account

# 需要导入模块: from djstripe.models import Charge [as 别名]
# 或者: from djstripe.models.Charge import _attach_objects_hook [as 别名]
	def test__attach_objects_hook_no_destination_account(
		self, mock_account, mock_payment_method, mock_charge_account, mock_charge_source
	):
		"""Test that _attach_objects_hook works as expected when there is no destination account."""
		charge = Charge(
			amount=50,
			currency="usd",
			id="ch_test",
			status=ChargeStatus.failed,
			captured=False,
			paid=False,
		)
		mock_cls = create_autospec(spec=Charge, spec_set=True)
		mock_cls._stripe_object_destination_to_account.return_value = False
		mock_data = {"source": {"object": "foo"}}
		mock_payment_method._get_or_create_source.return_value = ("bar", "unused")

		charge._attach_objects_hook(cls=mock_cls, data=mock_data)

		# expect the attributes to be set appropriately
		self.assertEqual(mock_account.get_default_account.return_value, charge.account)
		self.assertEqual(
			mock_payment_method._get_or_create_source.return_value[0], charge.source
		)
		# expect the appropriate calls to be made
		mock_cls._stripe_object_destination_to_account.assert_called_once_with(
			target_cls=mock_account, data=mock_data
		)
		mock_payment_method._get_or_create_source.assert_called_once_with(
			data=mock_data["source"], source_type=mock_data["source"]["object"]
		)
开发者ID:,项目名称:,代码行数:33,代码来源:


注:本文中的djstripe.models.Charge._attach_objects_hook方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。