Ai
1 Star 0 Fork 0

Adolph/shopify_python_api

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
limits_test.py 2.44 KB
一键复制 编辑 原始数据 按行查看 历史
Tyler Ball 提交于 2019-04-05 05:02 +08:00 . update limits.py and test
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())
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/chen_guo_hong/shopify_python_api.git
git@gitee.com:chen_guo_hong/shopify_python_api.git
chen_guo_hong
shopify_python_api
shopify_python_api
master

搜索帮助