【问题标题】:How can I patch the Stripe Subscription如何修补 Stripe 订阅
【发布时间】:2016-06-07 10:42:52
【问题描述】:

我正在为使用 Stripe 支付的模块编写测试。而且我想对其进行模拟,以使其不向 API 发送查询。 我使用下一个代码,但我仍然对 API 有查询。我不明白为什么?每次我运行测试时,此类查询都会出现在 Stripe 日志中:

/v1/customers/cus_*********/subscription

这是我的代码:

@patch('stripe.Subscription.save')
def test_subscription(self, subscription_update):
    subscription_update.return_value = self.convert_to_stripe_object({...})
    # there is test code

这是什么原因,我该如何修补该查询?感谢您的帮助!

【问题讨论】:

  • ` @patch('stripe.Plan.list') @patch('stripe.Customer.save') @patch('stripe.Customer.create') @patch('stripe.Token. create') @patch('stripe.Customer.delete') @patch('stripe.Plan.create') @patch('stripe.Plan.delete') `我使用上述所有方法进行修补,它可以正常工作在文档中描述。这很奇怪,但我在这里找不到需要的选项:stripe.com/docs/api/python#subscriptions

标签: python testing mocking patch


【解决方案1】:

我找到了解决办法。我修补了 update_subscription 函数:

@mock.patch.object(stripe.Customer, 'update_subscription', autospec=True)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-07-03
    • 2017-12-27
    • 2017-12-03
    • 2017-08-20
    • 2021-05-22
    • 2021-01-01
    • 2018-02-02
    • 2016-06-17
    相关资源
    最近更新 更多