lsrestclient 1.5.1__py3-none-any.whl → 2.0.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 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
@@ -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
- exceptions_by_class = {e.__name__: e for e in exceptions}
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
- mock_name: str
11
- client: LsRestClient
12
- mock: MagicMock
11
+ mock_name: str
12
+ client: LsRestClient
13
+ mock: MagicMock
13
14
 
14
15
 
15
16
  class LsRestClientMocker(object):
16
- def __init__(self):
17
- super().__init__()
18
- self.mocks = {}
17
+ def __init__(self):
18
+ super().__init__()
19
+ self.mocks = {}
19
20
 
20
- def mock(self, client: LsRestClient | str, method: str, url: str, *args, **kwargs):
21
- if isinstance(client, str):
22
- client = LsRestClient.client(client)
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
- mock_name = LsRestClient.mock_name(client.name, method, url)
25
- mock = MagicMock(*args, **kwargs)
26
- client.mock(mock_name, mock)
27
- self.mocks[mock_name] = LsRestClientMockModel(client=client, mock_name=mock_name, mock=mock)
28
- return mock
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
- def unmock_all(self):
31
- for mock_name, mock_model in self.mocks.items():
32
- mock_model.client.unmock(mock_name)
33
- self.mocks = {}
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
- def unmock(self, client: LsRestClient, method: str, url: str):
36
- mock_name = LsRestClient.mock_name(client.name, method, url)
37
- mock_model = self.mocks[mock_name]
38
- mock_model.client.unmock(mock_name)
39
- del self.mocks[mock_name]
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
- mocker = LsRestClientMocker()
45
- yield mocker
46
- mocker.unmock_all()
45
+ mocker = LsRestClientMocker()
46
+ yield mocker
47
+ mocker.unmock_all()
lsrestclient/response.py CHANGED
@@ -2,6 +2,7 @@ from dataclasses import dataclass
2
2
  from typing import Optional
3
3
 
4
4
  import lsjsonclasses
5
+ import pydash
5
6
  from requests import Response
6
7
  from requests.structures import CaseInsensitiveDict
7
8
 
@@ -33,9 +34,11 @@ class LsRestClientResponse:
33
34
  :return: An instance of LsRestClientResponse representing the response.
34
35
  :rtype: LsRestClientResponse
35
36
  """
37
+
38
+ encoding = pydash.get(response, "encoding", None)
36
39
  return cls(
37
40
  status_code=response.status_code,
38
- content=response.content.decode("utf8"),
41
+ content=response.content.decode("utf8" if encoding is None else encoding),
39
42
  headers=response.headers,
40
43
  )
41
44
 
@@ -1,16 +1,18 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lsrestclient
3
- Version: 1.5.1
3
+ Version: 2.0.0
4
4
  Summary: REST Api Client
5
5
  Author: mba
6
6
  Author-email: bartel@electronic-shop.lu
7
- Requires-Python: >=3.11,<4.0
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.0,<3.0.0)
11
- Requires-Dist: pydash (>=7.0.6,<8.0.0)
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.4,<2.0.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=Bj9X9jQT2hI0jbXrxDasjDczo3QVWAj_J6yaElBQegw,1923
10
+ lsrestclient-2.0.0.dist-info/METADATA,sha256=4JzX2tULgW7EnU5EQUHkhsoaRjNq3At3A7Y3O8KIAiU,6748
11
+ lsrestclient-2.0.0.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
12
+ lsrestclient-2.0.0.dist-info/entry_points.txt,sha256=7lN1XN3lq5Jv5PlpOdIlFrLlFlwzE5MaEWSgMhKASOM,47
13
+ lsrestclient-2.0.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=IXjIgb7ySF-1FdAtnOKRyF3k9LJRB3OFyzIIZI1GNxM,1816
10
- lsrestclient-1.5.1.dist-info/METADATA,sha256=6srj7rUx01jtO29kbyLMeKwclS7x2ND67E_P8GvOOSA,6656
11
- lsrestclient-1.5.1.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
12
- lsrestclient-1.5.1.dist-info/entry_points.txt,sha256=7lN1XN3lq5Jv5PlpOdIlFrLlFlwzE5MaEWSgMhKASOM,47
13
- lsrestclient-1.5.1.dist-info/RECORD,,