lsrestclient 1.5.2__py3-none-any.whl → 1.7.0__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- lsrestclient/client.py +2 -0
- lsrestclient/exceptions.py +7 -3
- lsrestclient/mock.py +27 -26
- lsrestclient/response.py +8 -2
- {lsrestclient-1.5.2.dist-info → lsrestclient-1.7.0.dist-info}/METADATA +7 -5
- lsrestclient-1.7.0.dist-info/RECORD +13 -0
- lsrestclient-1.5.2.dist-info/RECORD +0 -13
- {lsrestclient-1.5.2.dist-info → lsrestclient-1.7.0.dist-info}/WHEEL +0 -0
- {lsrestclient-1.5.2.dist-info → lsrestclient-1.7.0.dist-info}/entry_points.txt +0 -0
lsrestclient/client.py
CHANGED
@@ -66,6 +66,7 @@ class LsRestClient(Session):
|
|
66
66
|
self._mocks = {}
|
67
67
|
self.base_url = base_url
|
68
68
|
self.base_headers = {"content-type": "application/json"}
|
69
|
+
self.base_kwargs = {}
|
69
70
|
self.name = name
|
70
71
|
super().__init__()
|
71
72
|
self._clients[name] = self
|
@@ -164,6 +165,7 @@ class LsRestClient(Session):
|
|
164
165
|
|
165
166
|
headers = self.base_headers | bearer_headers | kwargs.get("headers", {})
|
166
167
|
|
168
|
+
kwargs |= self.base_kwargs
|
167
169
|
kwargs |= dict(headers=headers)
|
168
170
|
|
169
171
|
# params
|
lsrestclient/exceptions.py
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
import contextlib
|
2
|
+
import logging
|
2
3
|
from typing import Optional, List, Type
|
3
4
|
|
4
5
|
import pydash
|
5
6
|
from webexception.webexception import WebException
|
6
|
-
import logging
|
7
7
|
|
8
8
|
log = logging.getLogger(__name__)
|
9
9
|
|
@@ -43,8 +43,12 @@ class DownStreamError(Exception):
|
|
43
43
|
|
44
44
|
|
45
45
|
@contextlib.contextmanager
|
46
|
-
def raise_errors(r, exceptions: List[Type[Exception]]):
|
47
|
-
|
46
|
+
def raise_errors(r, exceptions: Optional[List[Type[Exception]]] = None):
|
47
|
+
if exceptions is None:
|
48
|
+
exceptions_by_class = {}
|
49
|
+
else:
|
50
|
+
exceptions_by_class = {e.__name__: e for e in exceptions}
|
51
|
+
|
48
52
|
if r.status_code < 399:
|
49
53
|
yield r
|
50
54
|
else:
|
lsrestclient/mock.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
import dataclasses
|
2
2
|
from contextlib import contextmanager
|
3
|
+
from typing import Union
|
3
4
|
from unittest.mock import MagicMock
|
4
5
|
|
5
6
|
from lsrestclient import LsRestClient
|
@@ -7,40 +8,40 @@ from lsrestclient import LsRestClient
|
|
7
8
|
|
8
9
|
@dataclasses.dataclass
|
9
10
|
class LsRestClientMockModel:
|
10
|
-
|
11
|
-
|
12
|
-
|
11
|
+
mock_name: str
|
12
|
+
client: LsRestClient
|
13
|
+
mock: MagicMock
|
13
14
|
|
14
15
|
|
15
16
|
class LsRestClientMocker(object):
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
def __init__(self):
|
18
|
+
super().__init__()
|
19
|
+
self.mocks = {}
|
19
20
|
|
20
|
-
|
21
|
-
|
22
|
-
|
21
|
+
def mock(self, client: Union[LsRestClient, str], method: str, url: str, *args, **kwargs):
|
22
|
+
if isinstance(client, str):
|
23
|
+
client = LsRestClient.client(client)
|
23
24
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
25
|
+
mock_name = LsRestClient.mock_name(client.name, method, url)
|
26
|
+
mock = MagicMock(*args, **kwargs)
|
27
|
+
client.mock(mock_name, mock)
|
28
|
+
self.mocks[mock_name] = LsRestClientMockModel(client=client, mock_name=mock_name, mock=mock)
|
29
|
+
return mock
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
def unmock_all(self):
|
32
|
+
for mock_name, mock_model in self.mocks.items():
|
33
|
+
mock_model.client.unmock(mock_name)
|
34
|
+
self.mocks = {}
|
34
35
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
36
|
+
def unmock(self, client: LsRestClient, method: str, url: str):
|
37
|
+
mock_name = LsRestClient.mock_name(client.name, method, url)
|
38
|
+
mock_model = self.mocks[mock_name]
|
39
|
+
mock_model.client.unmock(mock_name)
|
40
|
+
del self.mocks[mock_name]
|
40
41
|
|
41
42
|
|
42
43
|
@contextmanager
|
43
44
|
def lsrestclient_mock_context():
|
44
|
-
|
45
|
-
|
46
|
-
|
45
|
+
mocker = LsRestClientMocker()
|
46
|
+
yield mocker
|
47
|
+
mocker.unmock_all()
|
lsrestclient/response.py
CHANGED
@@ -6,7 +6,6 @@ import pydash
|
|
6
6
|
from requests import Response
|
7
7
|
from requests.structures import CaseInsensitiveDict
|
8
8
|
|
9
|
-
|
10
9
|
@dataclass
|
11
10
|
class LsRestClientResponse:
|
12
11
|
"""
|
@@ -36,9 +35,16 @@ class LsRestClientResponse:
|
|
36
35
|
"""
|
37
36
|
|
38
37
|
encoding = pydash.get(response, "encoding", None)
|
38
|
+
headers = pydash.get(response, "headers", None)
|
39
|
+
content_type = headers.get("Content-Type", None)
|
40
|
+
if content_type == 'application/pdf':
|
41
|
+
content = response.content
|
42
|
+
else:
|
43
|
+
content = response.content.decode("utf8" if encoding is None else encoding)
|
44
|
+
|
39
45
|
return cls(
|
40
46
|
status_code=response.status_code,
|
41
|
-
content=
|
47
|
+
content=content,
|
42
48
|
headers=response.headers,
|
43
49
|
)
|
44
50
|
|
@@ -1,16 +1,18 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: lsrestclient
|
3
|
-
Version: 1.
|
3
|
+
Version: 1.7.0
|
4
4
|
Summary: REST Api Client
|
5
5
|
Author: mba
|
6
6
|
Author-email: bartel@electronic-shop.lu
|
7
|
-
Requires-Python: >=3.
|
7
|
+
Requires-Python: >=3.9,<4.0
|
8
8
|
Classifier: Programming Language :: Python :: 3
|
9
|
+
Classifier: Programming Language :: Python :: 3.9
|
10
|
+
Classifier: Programming Language :: Python :: 3.10
|
9
11
|
Classifier: Programming Language :: Python :: 3.11
|
10
|
-
Requires-Dist: lsjsonclasses (>=2.0.
|
11
|
-
Requires-Dist: pydash (
|
12
|
+
Requires-Dist: lsjsonclasses (>=2.0.1,<3.0.0)
|
13
|
+
Requires-Dist: pydash (>4.0.0)
|
12
14
|
Requires-Dist: requests (>=2.31.0,<3.0.0)
|
13
|
-
Requires-Dist: webexception (>=1.0.
|
15
|
+
Requires-Dist: webexception (>=1.0.5,<2.0.0)
|
14
16
|
Description-Content-Type: text/markdown
|
15
17
|
|
16
18
|
# lsrestclient
|
@@ -0,0 +1,13 @@
|
|
1
|
+
lsrestclient/__init__.py,sha256=lI62SHmG0m-iukB5UEwdN5dO4cKnDasOt-TmR1rgaWI,72
|
2
|
+
lsrestclient/auth.py,sha256=n9f5GkKDbzin2jHNv9D7QBb6ZLEjamfbkzzlGpNdjLE,468
|
3
|
+
lsrestclient/client.py,sha256=44fUG8VOKkZIZM8d5EhqVE4rMmq32vLu_9yYXZWcHNg,11159
|
4
|
+
lsrestclient/contexts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
5
|
+
lsrestclient/contexts/bearer_token.py,sha256=GZZOzAI2Ng_9DvFCbhv1Wwb8wJ1AYCca3fQeNtt2NaU,753
|
6
|
+
lsrestclient/exceptions.py,sha256=IkIk9bLUHv_Ds9oJ24fbdpdP2nnoUQM5RGX25hzQSdI,2197
|
7
|
+
lsrestclient/fixtures.py,sha256=dFkAYQXL6xqTOwRofb03Nsu_cIjq1sG10Rh8dxWfz9s,239
|
8
|
+
lsrestclient/mock.py,sha256=Ya12F0t5sXHTSt-X4jDDj5ILJx6y6QaBAMXutQMsIRI,1376
|
9
|
+
lsrestclient/response.py,sha256=zVisLH4TMG5Ww9gseLSb1rVpHUESoR03DNpL0bv1GCU,2165
|
10
|
+
lsrestclient-1.7.0.dist-info/METADATA,sha256=JisXxDQLDg3Ygf9RBO8gEiVeEzty6edBYPFyybwF9BM,6748
|
11
|
+
lsrestclient-1.7.0.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
|
12
|
+
lsrestclient-1.7.0.dist-info/entry_points.txt,sha256=7lN1XN3lq5Jv5PlpOdIlFrLlFlwzE5MaEWSgMhKASOM,47
|
13
|
+
lsrestclient-1.7.0.dist-info/RECORD,,
|
@@ -1,13 +0,0 @@
|
|
1
|
-
lsrestclient/__init__.py,sha256=lI62SHmG0m-iukB5UEwdN5dO4cKnDasOt-TmR1rgaWI,72
|
2
|
-
lsrestclient/auth.py,sha256=n9f5GkKDbzin2jHNv9D7QBb6ZLEjamfbkzzlGpNdjLE,468
|
3
|
-
lsrestclient/client.py,sha256=BEywDmQ86XsIr8aVtrbXYmm-EBN7SN-fPrakbZ1ZpX8,11094
|
4
|
-
lsrestclient/contexts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
5
|
-
lsrestclient/contexts/bearer_token.py,sha256=GZZOzAI2Ng_9DvFCbhv1Wwb8wJ1AYCca3fQeNtt2NaU,753
|
6
|
-
lsrestclient/exceptions.py,sha256=Ze_UZutdTxmKXq8brvciZclUIkEGpmFrybPzk6TVk4Q,2105
|
7
|
-
lsrestclient/fixtures.py,sha256=dFkAYQXL6xqTOwRofb03Nsu_cIjq1sG10Rh8dxWfz9s,239
|
8
|
-
lsrestclient/mock.py,sha256=YanA_CQdaIMd99VkHaWDv3ro59fjBJsNUTZb14rC5aE,1213
|
9
|
-
lsrestclient/response.py,sha256=Bj9X9jQT2hI0jbXrxDasjDczo3QVWAj_J6yaElBQegw,1923
|
10
|
-
lsrestclient-1.5.2.dist-info/METADATA,sha256=CQxcyIzCgbTLuvd1atsfmvGUiXz1yNx74eMsWSJCQiU,6656
|
11
|
-
lsrestclient-1.5.2.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
|
12
|
-
lsrestclient-1.5.2.dist-info/entry_points.txt,sha256=7lN1XN3lq5Jv5PlpOdIlFrLlFlwzE5MaEWSgMhKASOM,47
|
13
|
-
lsrestclient-1.5.2.dist-info/RECORD,,
|
File without changes
|
File without changes
|