lsrestclient 1.1.0__tar.gz → 1.2.0__tar.gz
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.
- {lsrestclient-1.1.0 → lsrestclient-1.2.0}/PKG-INFO +1 -1
- {lsrestclient-1.1.0 → lsrestclient-1.2.0}/lsrestclient/client.py +4 -22
- lsrestclient-1.2.0/lsrestclient/fixtures.py +12 -0
- lsrestclient-1.2.0/lsrestclient/mock.py +36 -0
- {lsrestclient-1.1.0 → lsrestclient-1.2.0}/pyproject.toml +4 -1
- {lsrestclient-1.1.0 → lsrestclient-1.2.0}/README.md +0 -0
- {lsrestclient-1.1.0 → lsrestclient-1.2.0}/lsrestclient/__init__.py +0 -0
- {lsrestclient-1.1.0 → lsrestclient-1.2.0}/lsrestclient/auth.py +0 -0
- {lsrestclient-1.1.0 → lsrestclient-1.2.0}/lsrestclient/contexts/__init__.py +0 -0
- {lsrestclient-1.1.0 → lsrestclient-1.2.0}/lsrestclient/contexts/bearer_token.py +0 -0
- {lsrestclient-1.1.0 → lsrestclient-1.2.0}/lsrestclient/exceptions.py +0 -0
- {lsrestclient-1.1.0 → lsrestclient-1.2.0}/lsrestclient/response.py +0 -0
@@ -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,
|
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,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
|
[tool.poetry]
|
2
2
|
name = "lsrestclient"
|
3
|
-
version = "1.
|
3
|
+
version = "1.2.0"
|
4
4
|
description = "REST Api Client"
|
5
5
|
authors = ["mba <bartel@electronic-shop.lu>"]
|
6
6
|
readme = "README.md"
|
@@ -32,3 +32,6 @@ log_cli_format = "[%(levelname)8s] %(message)s (%(filename)s:%(lineno)s)"
|
|
32
32
|
|
33
33
|
[tool.black]
|
34
34
|
line-length = 120
|
35
|
+
|
36
|
+
[tool.poetry.plugins.pytest11]
|
37
|
+
"lsrestclient" = "lsrestclient"
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|