Skip to content

Commit 59bddcf

Browse files
Merge pull request #5 from canassa/add-timeout-parameter
Added timeout parameter
2 parents d257c44 + a1dcb71 commit 59bddcf

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

tests.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,27 @@ def test_with_ssl(self):
4444
)
4545
self.assertTrue(api.is_ssl, True)
4646

47+
def test_with_timeout(self):
48+
""" Test non-ssl """
49+
api = woocommerce.API(
50+
url="https://woo.test",
51+
consumer_key=self.consumer_key,
52+
consumer_secret=self.consumer_secret,
53+
timeout=10,
54+
)
55+
self.assertEqual(api.timeout, 10)
56+
57+
@all_requests
58+
def woo_test_mock(*args, **kwargs):
59+
""" URL Mock """
60+
return {'status_code': 200,
61+
'content': 'OK'}
62+
63+
with HTTMock(woo_test_mock):
64+
# call requests
65+
status = api.get("products").status_code
66+
self.assertEqual(status, 200)
67+
4768
def test_get(self):
4869
""" Test GET requests """
4970
@all_requests

woocommerce/api.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def __init__(self, url, consumer_key, consumer_secret, **kwargs):
2323
self.consumer_secret = consumer_secret
2424
self.version = kwargs.get("version", "v3")
2525
self.is_ssl = self.__is_ssl()
26+
self.timeout = kwargs.get("timeout")
2627
self.verify_ssl = kwargs.get("verify_ssl", True)
2728

2829
def __is_ssl(self):
@@ -74,6 +75,7 @@ def __request(self, method, endpoint, data):
7475
verify=self.verify_ssl,
7576
auth=auth,
7677
data=data,
78+
timeout=self.timeout,
7779
headers=headers
7880
)
7981

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy