代码拉取完成,页面将自动刷新
import shopify
from mock import patch
from test.test_helper import TestCase
class LimitsTest(TestCase):
"""
API Calls Limit Tests
Conversion of test/limits_test.rb
"""
@classmethod
def setUpClass(self):
self.original_headers = None
def setUp(self):
super(LimitsTest, self).setUp()
self.fake('shop')
shopify.Shop.current()
# TODO: Fake not support Headers
self.original_headers = shopify.Shop.connection.response.headers
def tearDown(self):
super(LimitsTest, self).tearDown()
shopify.Shop.connection.response.headers = self.original_headers
def test_raise_error_no_header(self):
with self.assertRaises(Exception):
shopify.Limits.credit_left()
def test_raise_error_invalid_header(self):
with patch.dict(
shopify.Shop.connection.response.headers,
{'bad': 'value'},
clear=True):
with self.assertRaises(Exception):
shopify.Limits.credit_left()
def test_fetch_limits_total(self):
with patch.dict(
shopify.Shop.connection.response.headers,
{'X-Shopify-Shop-Api-Call-Limit': '40/40'},
clear=True):
self.assertEqual(40, shopify.Limits.credit_limit())
def test_fetch_used_calls(self):
with patch.dict(
shopify.Shop.connection.response.headers,
{'X-Shopify-Shop-Api-Call-Limit': '1/40'},
clear=True):
self.assertEqual(1, shopify.Limits.credit_used())
def test_calculate_remaining_calls(self):
with patch.dict(
shopify.Shop.connection.response.headers,
{'X-Shopify-Shop-Api-Call-Limit': '292/300'},
clear=True):
self.assertEqual(8, shopify.Limits.credit_left())
def test_maxed_credits_false(self):
with patch.dict(
shopify.Shop.connection.response.headers,
{'X-Shopify-Shop-Api-Call-Limit': '125/300'},
clear=True):
self.assertFalse(shopify.Limits.credit_maxed())
def test_maxed_credits_true(self):
with patch.dict(
shopify.Shop.connection.response.headers,
{'X-Shopify-Shop-Api-Call-Limit': '40/40'},
clear=True):
self.assertTrue(shopify.Limits.credit_maxed())
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。