paddle-python-sdk 0.2.1__py3-none-any.whl → 0.2.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- paddle_billing/Client.py +4 -2
- {paddle_python_sdk-0.2.1.dist-info → paddle_python_sdk-0.2.2.dist-info}/METADATA +1 -1
- {paddle_python_sdk-0.2.1.dist-info → paddle_python_sdk-0.2.2.dist-info}/RECORD +8 -8
- {paddle_python_sdk-0.2.1.dist-info → paddle_python_sdk-0.2.2.dist-info}/WHEEL +1 -1
- tests/Functional/Client/test_Client.py +30 -0
- tests/Utils/TestClient.py +13 -7
- {paddle_python_sdk-0.2.1.dist-info → paddle_python_sdk-0.2.2.dist-info}/LICENSE +0 -0
- {paddle_python_sdk-0.2.1.dist-info → paddle_python_sdk-0.2.2.dist-info}/top_level.txt +0 -0
paddle_billing/Client.py
CHANGED
|
@@ -50,6 +50,7 @@ class Client:
|
|
|
50
50
|
logger: Logger = None,
|
|
51
51
|
retry_count: int = 3,
|
|
52
52
|
use_api_version: int = 1,
|
|
53
|
+
timeout: float = 60.0,
|
|
53
54
|
):
|
|
54
55
|
self.__api_key = api_key
|
|
55
56
|
self.retry_count = retry_count
|
|
@@ -58,6 +59,7 @@ class Client:
|
|
|
58
59
|
self.options = options if options else Options()
|
|
59
60
|
self.log = logger if logger else Client.null_logger()
|
|
60
61
|
self.client = http_client if http_client else self.build_request_session()
|
|
62
|
+
self.timeout = timeout
|
|
61
63
|
self.payload = None # Used by pytest
|
|
62
64
|
self.status_code = None # Used by pytest
|
|
63
65
|
|
|
@@ -133,7 +135,7 @@ class Client:
|
|
|
133
135
|
self.payload = self.serialize_json_payload(payload) if payload else None
|
|
134
136
|
try:
|
|
135
137
|
# We use data= instead of json= because we manually serialize data into JSON
|
|
136
|
-
response = self.client.request(method.upper(), url, data=self.payload)
|
|
138
|
+
response = self.client.request(method.upper(), url, data=self.payload, timeout=self.timeout)
|
|
137
139
|
self.status_code = response.status_code
|
|
138
140
|
response.raise_for_status()
|
|
139
141
|
|
|
@@ -204,7 +206,7 @@ class Client:
|
|
|
204
206
|
'Authorization': f"Bearer {self.__api_key}",
|
|
205
207
|
'Content-Type': 'application/json',
|
|
206
208
|
'Paddle-Version': str(self.use_api_version),
|
|
207
|
-
'User-Agent': 'PaddleSDK/python 0.2.
|
|
209
|
+
'User-Agent': 'PaddleSDK/python 0.2.2',
|
|
208
210
|
})
|
|
209
211
|
|
|
210
212
|
# Configure retries
|
|
@@ -3,7 +3,7 @@ examples/catalog_management.py,sha256=3osNPpYD5Dh3uq3Uf7Be9li806IkLbr8W7iRJMHMJJ
|
|
|
3
3
|
examples/event_polling.py,sha256=XIpNzSfFIF_V72a-Fujal7y43PV4K28CCt0K29goz_Y,2407
|
|
4
4
|
examples/get_products.py,sha256=LqA92ykNCJJmkTQIpnqrun7HaXozh3h0BpQ4S2JnsR0,1858
|
|
5
5
|
examples/logger.py,sha256=mZuSjhKSqUYpAGtvcqmazkU8Eb7jzl_MS2zNUPFNvY0,1065
|
|
6
|
-
paddle_billing/Client.py,sha256=
|
|
6
|
+
paddle_billing/Client.py,sha256=oraUhJvIQQSj7OdgXMRZBmx4agyRLnwGGjdvR-P6rE0,9054
|
|
7
7
|
paddle_billing/ConditionallyRemoveImportMeta.py,sha256=tyCEj29dCDO3s_28NwBITRzU0ms2o9x0uToDpsufaEo,652
|
|
8
8
|
paddle_billing/EnumStringify.py,sha256=iDvKULZat3jx9A-_PhvoN6CbFGf2pyxrQeYZxqX9n8M,48
|
|
9
9
|
paddle_billing/Environment.py,sha256=qMhuIUPbKRrHoHLmX_0k4XaowDpr8d-RlNPc0iyOh9A,424
|
|
@@ -467,7 +467,7 @@ tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
|
467
467
|
tests/conftest.py,sha256=K_rWFm4jOBGVpoQP9llOwQwyYrXThbF3CBvood_hNRU,127
|
|
468
468
|
tests/Functional/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
469
469
|
tests/Functional/Client/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
470
|
-
tests/Functional/Client/test_Client.py,sha256=
|
|
470
|
+
tests/Functional/Client/test_Client.py,sha256=y7T4UL7mgoxDxg7eQzjrbaOhcc0xS6YBitoNG817MhY,6450
|
|
471
471
|
tests/Functional/Resources/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
472
472
|
tests/Functional/Resources/Addresses/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
473
473
|
tests/Functional/Resources/Addresses/test_AddressesClient.py,sha256=hnSEvZS6mbkFQkFr52w2OfTWVl6uP5LnAFC0jiXf0bY,16313
|
|
@@ -510,11 +510,11 @@ tests/Unit/PaddleStrEnum/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZ
|
|
|
510
510
|
tests/Unit/PaddleStrEnum/test_PaddleStrEnum.py,sha256=014AQnElUI3J9amjg-qRCZ1aCw52JLrU98z_bbVRyrc,3145
|
|
511
511
|
tests/Utils/FakeResponse.py,sha256=naT8IgXDtbAxAAj-T3FoJl9Ze4kXb-O-Mf6BarWU6oM,305
|
|
512
512
|
tests/Utils/ReadsFixture.py,sha256=VEIEST29lorMZHA11XYn7aqtEYry2TDUqeWd63IRLbM,1153
|
|
513
|
-
tests/Utils/TestClient.py,sha256=
|
|
513
|
+
tests/Utils/TestClient.py,sha256=frMWf0J-C2o8KUKGY5jzBoVPHsdYq_dTMVClavBvcQY,1569
|
|
514
514
|
tests/Utils/TestLogger.py,sha256=h6PJbVrgxyi_H0FlSoSKwONOqBC35Hdmqp8_TZ5qt_w,557
|
|
515
515
|
tests/Utils/__init__.py,sha256=fkxfGYArVZPD7GQlBEwT6FY052mTD83VnDerzsTK7hA,39
|
|
516
|
-
paddle_python_sdk-0.2.
|
|
517
|
-
paddle_python_sdk-0.2.
|
|
518
|
-
paddle_python_sdk-0.2.
|
|
519
|
-
paddle_python_sdk-0.2.
|
|
520
|
-
paddle_python_sdk-0.2.
|
|
516
|
+
paddle_python_sdk-0.2.2.dist-info/LICENSE,sha256=e5Sn9mzCdpjnqCLxXpGHNKdYB6JlRSTLhN_CD4WSO6w,10770
|
|
517
|
+
paddle_python_sdk-0.2.2.dist-info/METADATA,sha256=akrC0oUB11WCjWXQ9IYZEMRbP46bqtlfU9w2DHFI0Y4,7247
|
|
518
|
+
paddle_python_sdk-0.2.2.dist-info/WHEEL,sha256=uCRv0ZEik_232NlR4YDw4Pv3Ajt5bKvMH13NUU7hFuI,91
|
|
519
|
+
paddle_python_sdk-0.2.2.dist-info/top_level.txt,sha256=9a07VPng7o5wK8VAXkl6NC30xrNbW9zff_02jHyHi4c,30
|
|
520
|
+
paddle_python_sdk-0.2.2.dist-info/RECORD,,
|
|
@@ -8,6 +8,7 @@ from paddle_billing.Exceptions.ApiErrors.AddressApiError import AddressApiError
|
|
|
8
8
|
from requests.exceptions import RequestException, HTTPError
|
|
9
9
|
|
|
10
10
|
from tests.Utils.TestLogger import test_log_handler, LogHandler
|
|
11
|
+
from tests.Utils.TestClient import TestClient as UtilsTestClient
|
|
11
12
|
|
|
12
13
|
|
|
13
14
|
class TestClient:
|
|
@@ -136,3 +137,32 @@ class TestClient:
|
|
|
136
137
|
|
|
137
138
|
assert test_log_handler.get_logs()[0].message == \
|
|
138
139
|
f"Request failed: {expected_response_status} Client Error: {expected_reason} for url: {expected_request_url}. {api_error.detail}"
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
def test_client_with_custom_timeout(
|
|
143
|
+
self,
|
|
144
|
+
mock_requests
|
|
145
|
+
):
|
|
146
|
+
test_client = UtilsTestClient(timeout=99)
|
|
147
|
+
|
|
148
|
+
expected_request_url = f"{test_client.base_url}/some/url"
|
|
149
|
+
|
|
150
|
+
mock_requests.post(expected_request_url, status_code=200)
|
|
151
|
+
|
|
152
|
+
test_client.client.post_raw(expected_request_url)
|
|
153
|
+
|
|
154
|
+
assert mock_requests.last_request.timeout == 99
|
|
155
|
+
|
|
156
|
+
|
|
157
|
+
def test_client_default_timeout(
|
|
158
|
+
self,
|
|
159
|
+
test_client,
|
|
160
|
+
mock_requests
|
|
161
|
+
):
|
|
162
|
+
expected_request_url = f"{test_client.base_url}/some/url"
|
|
163
|
+
|
|
164
|
+
mock_requests.post(expected_request_url, status_code=200)
|
|
165
|
+
|
|
166
|
+
test_client.client.post_raw(expected_request_url)
|
|
167
|
+
|
|
168
|
+
assert mock_requests.last_request.timeout == 60.0
|
tests/Utils/TestClient.py
CHANGED
|
@@ -15,10 +15,11 @@ class TestClient:
|
|
|
15
15
|
api_secret_key: str | None = None,
|
|
16
16
|
environment: Environment = Environment.SANDBOX,
|
|
17
17
|
logger: Logger | None = None,
|
|
18
|
+
timeout: float | None = None,
|
|
18
19
|
):
|
|
19
20
|
self._environment = environment
|
|
20
21
|
self._base_url = self._environment.base_url
|
|
21
|
-
self._client = client or self.create_client(api_secret_key, logger)
|
|
22
|
+
self._client = client or self.create_client(api_secret_key, logger, timeout)
|
|
22
23
|
|
|
23
24
|
|
|
24
25
|
@property
|
|
@@ -34,12 +35,17 @@ class TestClient:
|
|
|
34
35
|
return self._environment
|
|
35
36
|
|
|
36
37
|
|
|
37
|
-
def create_client(self, api_secret_key: str | None = None, logger: Logger | None = None):
|
|
38
|
-
|
|
39
|
-
getenv('PADDLE_API_SECRET_KEY') if api_secret_key is None else api_secret_key,
|
|
40
|
-
options
|
|
41
|
-
logger
|
|
42
|
-
|
|
38
|
+
def create_client(self, api_secret_key: str | None = None, logger: Logger | None = None, timeout = None):
|
|
39
|
+
config = {
|
|
40
|
+
"api_key": getenv('PADDLE_API_SECRET_KEY') if api_secret_key is None else api_secret_key,
|
|
41
|
+
"options": Options(self._environment),
|
|
42
|
+
"logger": logger,
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if timeout is not None:
|
|
46
|
+
config["timeout"] = timeout
|
|
47
|
+
|
|
48
|
+
return Client(**config)
|
|
43
49
|
|
|
44
50
|
|
|
45
51
|
@fixture(autouse=True)
|
|
File without changes
|
|
File without changes
|