forked from Shopify/shopify_python_api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlimits_test.py
More file actions
65 lines (52 loc) · 2.19 KB
/
limits_test.py
File metadata and controls
65 lines (52 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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())