Skip to content

Commit e38b642

Browse files
committed
Made a new function for Session/Retry + formatted with black
1 parent bea5c02 commit e38b642

File tree

4 files changed

+125
-116
lines changed

4 files changed

+125
-116
lines changed

setup.py

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
# Get version from __init__.py file
1111
VERSION = ""
1212
with open("woocommerce/__init__.py", "r") as fd:
13-
VERSION = re.search(r"^__version__\s*=\s*['\"]([^\"]*)['\"]", fd.read(), re.MULTILINE).group(1)
13+
VERSION = re.search(
14+
r"^__version__\s*=\s*['\"]([^\"]*)['\"]", fd.read(), re.MULTILINE
15+
).group(1)
1416

1517
if not VERSION:
1618
raise RuntimeError("Cannot find version information")
@@ -30,14 +32,10 @@
3032
author_email="claudio+pypi@automattic.com",
3133
url="https://github.com/woocommerce/wc-api-python",
3234
license="MIT License",
33-
packages=[
34-
"woocommerce"
35-
],
35+
packages=["woocommerce"],
3636
include_package_data=True,
37-
platforms=['any'],
38-
install_requires=[
39-
"requests"
40-
],
37+
platforms=["any"],
38+
install_requires=["requests"],
4139
python_requires=">=3.6",
4240
classifiers=[
4341
"Development Status :: 5 - Production/Stable",
@@ -50,12 +48,12 @@
5048
"Programming Language :: Python :: 3.8",
5149
"Programming Language :: Python :: 3.9",
5250
"Programming Language :: Python :: 3.10",
53-
"Topic :: Software Development :: Libraries :: Python Modules"
51+
"Topic :: Software Development :: Libraries :: Python Modules",
5452
],
55-
keywords='woocommerce rest api',
53+
keywords="woocommerce rest api",
5654
project_urls={
57-
'Documentation': 'https://woocommerce.github.io/woocommerce-rest-api-docs/?python#libraries-and-tools',
58-
'Source': 'https://github.com/woocommerce/wc-api-python',
59-
'Tracker': 'https://github.com/woocommerce/wc-api-python/issues',
55+
"Documentation": "https://woocommerce.github.io/woocommerce-rest-api-docs/?python#libraries-and-tools",
56+
"Source": "https://github.com/woocommerce/wc-api-python",
57+
"Tracker": "https://github.com/woocommerce/wc-api-python/issues",
6058
},
6159
)

test_api.py

Lines changed: 51 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -16,39 +16,39 @@ def setUp(self):
1616
self.api = woocommerce.API(
1717
url="http://woo.test",
1818
consumer_key=self.consumer_key,
19-
consumer_secret=self.consumer_secret
19+
consumer_secret=self.consumer_secret,
2020
)
2121

2222
def test_version(self):
23-
""" Test default version """
23+
"""Test default version"""
2424
api = woocommerce.API(
2525
url="https://woo.test",
2626
consumer_key=self.consumer_key,
27-
consumer_secret=self.consumer_secret
27+
consumer_secret=self.consumer_secret,
2828
)
2929

3030
self.assertEqual(api.version, "wc/v3")
3131

3232
def test_non_ssl(self):
33-
""" Test non-ssl """
33+
"""Test non-ssl"""
3434
api = woocommerce.API(
3535
url="http://woo.test",
3636
consumer_key=self.consumer_key,
37-
consumer_secret=self.consumer_secret
37+
consumer_secret=self.consumer_secret,
3838
)
3939
self.assertFalse(api.is_ssl)
4040

4141
def test_with_ssl(self):
42-
""" Test ssl """
42+
"""Test ssl"""
4343
api = woocommerce.API(
4444
url="https://woo.test",
4545
consumer_key=self.consumer_key,
46-
consumer_secret=self.consumer_secret
46+
consumer_secret=self.consumer_secret,
4747
)
4848
self.assertTrue(api.is_ssl, True)
4949

5050
def test_with_timeout(self):
51-
""" Test timeout """
51+
"""Test timeout"""
5252
api = woocommerce.API(
5353
url="https://woo.test",
5454
consumer_key=self.consumer_key,
@@ -59,105 +59,114 @@ def test_with_timeout(self):
5959

6060
@all_requests
6161
def woo_test_mock(*args, **kwargs):
62-
""" URL Mock """
63-
return {'status_code': 200,
64-
'content': 'OK'}
62+
"""URL Mock"""
63+
return {"status_code": 200, "content": "OK"}
6564

6665
with HTTMock(woo_test_mock):
6766
# call requests
6867
status = api.get("products").status_code
6968
self.assertEqual(status, 200)
7069

7170
def test_get(self):
72-
""" Test GET requests """
71+
"""Test GET requests"""
72+
7373
@all_requests
7474
def woo_test_mock(*args, **kwargs):
75-
""" URL Mock """
76-
return {'status_code': 200,
77-
'content': 'OK'}
75+
"""URL Mock"""
76+
return {"status_code": 200, "content": "OK"}
7877

7978
with HTTMock(woo_test_mock):
8079
# call requests
8180
status = self.api.get("products").status_code
8281
self.assertEqual(status, 200)
8382

8483
def test_get_with_parameters(self):
85-
""" Test GET requests w/ url params """
84+
"""Test GET requests w/ url params"""
85+
8686
@all_requests
8787
def woo_test_mock(*args, **kwargs):
88-
return {'status_code': 200,
89-
'content': 'OK'}
88+
return {"status_code": 200, "content": "OK"}
9089

9190
with HTTMock(woo_test_mock):
9291
# call requests
93-
status = self.api.get("products", params={"per_page": 10, "page": 1, "offset": 0}).status_code
92+
status = self.api.get(
93+
"products", params={"per_page": 10, "page": 1, "offset": 0}
94+
).status_code
9495
self.assertEqual(status, 200)
9596

9697
def test_get_with_requests_kwargs(self):
97-
""" Test GET requests w/ optional requests-module kwargs """
98+
"""Test GET requests w/ optional requests-module kwargs"""
9899

99100
@all_requests
100101
def woo_test_mock(*args, **kwargs):
101-
return {'status_code': 200,
102-
'content': 'OK'}
102+
return {"status_code": 200, "content": "OK"}
103103

104104
with HTTMock(woo_test_mock):
105105
# call requests
106106
status = self.api.get("products", allow_redirects=True).status_code
107107
self.assertEqual(status, 200)
108108

109109
def test_post(self):
110-
""" Test POST requests """
110+
"""Test POST requests"""
111+
111112
@all_requests
112113
def woo_test_mock(*args, **kwargs):
113-
""" URL Mock """
114-
return {'status_code': 201,
115-
'content': 'OK'}
114+
"""URL Mock"""
115+
return {"status_code": 201, "content": "OK"}
116116

117117
with HTTMock(woo_test_mock):
118118
# call requests
119119
status = self.api.post("products", {}).status_code
120120
self.assertEqual(status, 201)
121121

122122
def test_put(self):
123-
""" Test PUT requests """
123+
"""Test PUT requests"""
124+
124125
@all_requests
125126
def woo_test_mock(*args, **kwargs):
126-
""" URL Mock """
127-
return {'status_code': 200,
128-
'content': 'OK'}
127+
"""URL Mock"""
128+
return {"status_code": 200, "content": "OK"}
129129

130130
with HTTMock(woo_test_mock):
131131
# call requests
132132
status = self.api.put("products", {}).status_code
133133
self.assertEqual(status, 200)
134134

135135
def test_delete(self):
136-
""" Test DELETE requests """
136+
"""Test DELETE requests"""
137+
137138
@all_requests
138139
def woo_test_mock(*args, **kwargs):
139-
""" URL Mock """
140-
return {'status_code': 200,
141-
'content': 'OK'}
140+
"""URL Mock"""
141+
return {"status_code": 200, "content": "OK"}
142142

143143
with HTTMock(woo_test_mock):
144144
# call requests
145145
status = self.api.delete("products").status_code
146146
self.assertEqual(status, 200)
147147

148148
def test_oauth_sorted_params(self):
149-
""" Test order of parameters for OAuth signature """
149+
"""Test order of parameters for OAuth signature"""
150+
150151
def check_sorted(keys, expected):
151152
params = oauth.OrderedDict()
152153
for key in keys:
153-
params[key] = ''
154+
params[key] = ""
154155

155156
ordered = list(oauth.OAuth.sorted_params(params).keys())
156157
self.assertEqual(ordered, expected)
157158

158-
check_sorted(['a', 'b'], ['a', 'b'])
159-
check_sorted(['b', 'a'], ['a', 'b'])
160-
check_sorted(['a', 'b[a]', 'b[b]', 'b[c]', 'c'], ['a', 'b[a]', 'b[b]', 'b[c]', 'c'])
161-
check_sorted(['a', 'b[c]', 'b[a]', 'b[b]', 'c'], ['a', 'b[c]', 'b[a]', 'b[b]', 'c'])
162-
check_sorted(['d', 'b[c]', 'b[a]', 'b[b]', 'c'], ['b[c]', 'b[a]', 'b[b]', 'c', 'd'])
163-
check_sorted(['a1', 'b[c]', 'b[a]', 'b[b]', 'a2'], ['a1', 'a2', 'b[c]', 'b[a]', 'b[b]'])
159+
check_sorted(["a", "b"], ["a", "b"])
160+
check_sorted(["b", "a"], ["a", "b"])
161+
check_sorted(
162+
["a", "b[a]", "b[b]", "b[c]", "c"], ["a", "b[a]", "b[b]", "b[c]", "c"]
163+
)
164+
check_sorted(
165+
["a", "b[c]", "b[a]", "b[b]", "c"], ["a", "b[c]", "b[a]", "b[b]", "c"]
166+
)
167+
check_sorted(
168+
["d", "b[c]", "b[a]", "b[b]", "c"], ["b[c]", "b[a]", "b[b]", "c", "d"]
169+
)
170+
check_sorted(
171+
["a1", "b[c]", "b[a]", "b[b]", "a2"], ["a1", "a2", "b[c]", "b[a]", "b[b]"]
172+
)

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