lsrestclient 1.1.0__py3-none-any.whl → 1.2.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
@@ -71,8 +71,8 @@ class LsRestClient(Session):
71
71
  self._clients[name] = self
72
72
 
73
73
  @staticmethod
74
- def mock_name(method: str, url: str) -> str:
75
- return f"{method.upper()}_{url}"
74
+ def mock_name(client_name: str, method: str, url: str) -> str:
75
+ return f"{client_name}_{method.upper()}_{url}"
76
76
 
77
77
  def full_url(
78
78
  self,
@@ -99,7 +99,7 @@ class LsRestClient(Session):
99
99
 
100
100
  def caller(self, method: str, url: str, *args, **kwargs) -> LsRestClientResponse:
101
101
  # check mocks
102
- mock = self._mocks.get(self.mock_name(method, url), None)
102
+ mock = self._mocks.get(self.mock_name(self.name, method, url), None)
103
103
  func = mock if mock is not None else self.request
104
104
  return func(method, url, *args, **kwargs)
105
105
 
@@ -251,27 +251,9 @@ class LsRestClient(Session):
251
251
  """
252
252
  return self.request("HEAD", *args, **kwargs)
253
253
 
254
- def mock(self, method: str, url: str, *args, **kwargs):
255
- mock_name = self.mock_name(method, url)
256
- mock = MagicMock(*args, **kwargs)
257
- # mock = MagicMock(self, mock_name, *args, **kwargs)
254
+ def mock(self, mock_name: str, mock: MagicMock):
258
255
  self._mocks[mock_name] = mock
259
- return LsRestClientMock(self, mock_name, mock)
260
256
 
261
257
  def unmock(self, mock_name: str):
262
258
  if mock_name in self._mocks:
263
259
  del self._mocks[mock_name]
264
-
265
-
266
- class LsRestClientMock(object):
267
- def __init__(self, client, mock_name, mock):
268
- self._client = client
269
- self._mock_name = mock_name
270
- self.mock = mock
271
-
272
- def unmock(self):
273
- self._client.unmock(self._mock_name)
274
-
275
- @property
276
- def call_count(self):
277
- return self.mock.call_count
@@ -0,0 +1,12 @@
1
+ from lsrestclient.mock import lsrestclient_mock_context
2
+
3
+ try:
4
+ import pytest
5
+
6
+ @pytest.fixture
7
+ def lsrestclient_mocker():
8
+ with lsrestclient_mock_context() as mocker:
9
+ yield mocker
10
+
11
+ except ImportError:
12
+ pass
lsrestclient/mock.py ADDED
@@ -0,0 +1,36 @@
1
+ import dataclasses
2
+ from contextlib import contextmanager
3
+ from unittest.mock import MagicMock
4
+
5
+ from lsrestclient import LsRestClient
6
+
7
+
8
+ @dataclasses.dataclass
9
+ class LsRestClientMockModel:
10
+ mock_name: str
11
+ client: LsRestClient
12
+ mock: MagicMock
13
+
14
+
15
+ class LsRestClientMocker(object):
16
+ def __init__(self):
17
+ super().__init__()
18
+ self.mocks = {}
19
+
20
+ def mock(self, client: LsRestClient, method: str, url: str, *args, **kwargs):
21
+ mock_name = LsRestClient.mock_name(client.name, method, url)
22
+ mock = MagicMock(*args, **kwargs)
23
+ client.mock(mock_name, mock)
24
+ self.mocks[mock_name] = LsRestClientMockModel(client=client, mock_name=mock_name, mock=mock)
25
+ return mock
26
+
27
+ def unmock_all(self):
28
+ for mock_name, mock_model in self.mocks.items():
29
+ mock_model.client.unmock(mock_name)
30
+
31
+
32
+ @contextmanager
33
+ def lsrestclient_mock_context():
34
+ mocker = LsRestClientMocker()
35
+ yield mocker
36
+ mocker.unmock_all()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lsrestclient
3
- Version: 1.1.0
3
+ Version: 1.2.0
4
4
  Summary: REST Api Client
5
5
  Author: mba
6
6
  Author-email: bartel@electronic-shop.lu
@@ -0,0 +1,13 @@
1
+ lsrestclient/__init__.py,sha256=lI62SHmG0m-iukB5UEwdN5dO4cKnDasOt-TmR1rgaWI,72
2
+ lsrestclient/auth.py,sha256=-XT9OajBudLDZJ7tZyM0E5EXF2R1Kc-jyeKMf24wyJA,403
3
+ lsrestclient/client.py,sha256=cQXgRZ7oktHR7u8i9sib9FhBV5JxdmA-QOz6UGkYzUc,9922
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=2Nw3eISrpBCdhHWOZTBjttEtPkJmTpRoPis72VO-R_g,979
7
+ lsrestclient/fixtures.py,sha256=dFkAYQXL6xqTOwRofb03Nsu_cIjq1sG10Rh8dxWfz9s,239
8
+ lsrestclient/mock.py,sha256=T9QYFdkKidLLKOeQMhwvMYY5pANQpHLXmkcLOtxd5Q4,971
9
+ lsrestclient/response.py,sha256=IXjIgb7ySF-1FdAtnOKRyF3k9LJRB3OFyzIIZI1GNxM,1816
10
+ lsrestclient-1.2.0.dist-info/METADATA,sha256=dRRu2ymZD198uSbOuF3Fjmmn1Sd2z0nRCb6lj44KOqg,6672
11
+ lsrestclient-1.2.0.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
12
+ lsrestclient-1.2.0.dist-info/entry_points.txt,sha256=zyMRgI1XpL7R013uDs4KUVTa1XL7AfzJ_-LfRPgFCXM,38
13
+ lsrestclient-1.2.0.dist-info/RECORD,,
@@ -0,0 +1,3 @@
1
+ [pytest11]
2
+ lsrestclient=lsrestclient
3
+
@@ -1,10 +0,0 @@
1
- lsrestclient/__init__.py,sha256=lI62SHmG0m-iukB5UEwdN5dO4cKnDasOt-TmR1rgaWI,72
2
- lsrestclient/auth.py,sha256=-XT9OajBudLDZJ7tZyM0E5EXF2R1Kc-jyeKMf24wyJA,403
3
- lsrestclient/client.py,sha256=--SPROODLa_cD3QPoca1OuW8qAdB8n7ynMVTfRTVs4E,10411
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=2Nw3eISrpBCdhHWOZTBjttEtPkJmTpRoPis72VO-R_g,979
7
- lsrestclient/response.py,sha256=IXjIgb7ySF-1FdAtnOKRyF3k9LJRB3OFyzIIZI1GNxM,1816
8
- lsrestclient-1.1.0.dist-info/METADATA,sha256=7uyNrZWkMvRicxlAxzZ4OTVoZMMrPQRJPybDADUgRU8,6672
9
- lsrestclient-1.1.0.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
10
- lsrestclient-1.1.0.dist-info/RECORD,,