lsrestclient 1.3.0__py3-none-any.whl → 1.3.2__py3-none-any.whl
Sign up to get free protection for your applications and to get access to all the features.
- lsrestclient/auth.py +6 -2
- lsrestclient/exceptions.py +9 -5
- lsrestclient/mock.py +27 -24
- {lsrestclient-1.3.0.dist-info → lsrestclient-1.3.2.dist-info}/METADATA +1 -1
- {lsrestclient-1.3.0.dist-info → lsrestclient-1.3.2.dist-info}/RECORD +7 -7
- {lsrestclient-1.3.0.dist-info → lsrestclient-1.3.2.dist-info}/WHEEL +0 -0
- {lsrestclient-1.3.0.dist-info → lsrestclient-1.3.2.dist-info}/entry_points.txt +0 -0
lsrestclient/auth.py
CHANGED
@@ -1,10 +1,14 @@
|
|
1
1
|
from lsrestclient import LsRestClient, DownStreamError
|
2
2
|
|
3
3
|
|
4
|
-
def
|
4
|
+
def auth_am_login(**kwargs) -> str:
|
5
5
|
am = LsRestClient.from_env("AM_BASE_URL", "am", True)
|
6
|
-
r = am.post("/auth/login", body=
|
6
|
+
r = am.post("/auth/login", body=kwargs)
|
7
7
|
if r.status_code == 200:
|
8
8
|
return r.json().get("access_token")
|
9
9
|
else:
|
10
10
|
raise DownStreamError("/auth/login", r.status_code, r.content)
|
11
|
+
|
12
|
+
|
13
|
+
def auth_am_login_apikey(org_id: str, api_key: str) -> str:
|
14
|
+
return auth_am_login(ORG_ID=org_id, API_KEY=api_key)
|
lsrestclient/exceptions.py
CHANGED
@@ -13,13 +13,13 @@ class ConnectionError(Exception):
|
|
13
13
|
"""Exception class for connection errors.
|
14
14
|
|
15
15
|
Args:
|
16
|
-
|
16
|
+
url (Optional[str]): The URL that the connection could not be established to.
|
17
17
|
|
18
18
|
Attributes:
|
19
|
-
|
19
|
+
url (Optional[str]): The URL that the connection could not be established to.
|
20
20
|
|
21
21
|
Raises:
|
22
|
-
|
22
|
+
ConnectionError: If a connection could not be established to the given URL.
|
23
23
|
|
24
24
|
"""
|
25
25
|
|
@@ -51,8 +51,12 @@ def raise_errors(r, exceptions: List[Type[Exception]]):
|
|
51
51
|
try:
|
52
52
|
json = r.json()
|
53
53
|
detail = pydash.get(json, "detail", json)
|
54
|
-
error_class = pydash.get(detail, "error_class")
|
55
|
-
|
54
|
+
error_class = pydash.get(detail, "error_class", None)
|
55
|
+
if error_class is not None:
|
56
|
+
payload = pydash.get(detail, "error_payload", {})
|
57
|
+
else:
|
58
|
+
error_class = pydash.get(detail, "ERROR_CLASS", None)
|
59
|
+
payload = {}
|
56
60
|
|
57
61
|
if error_class in exceptions_by_class:
|
58
62
|
e = exceptions_by_class[error_class](**payload)
|
lsrestclient/mock.py
CHANGED
@@ -7,37 +7,40 @@ from lsrestclient import LsRestClient
|
|
7
7
|
|
8
8
|
@dataclasses.dataclass
|
9
9
|
class LsRestClientMockModel:
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
mock_name: str
|
11
|
+
client: LsRestClient
|
12
|
+
mock: MagicMock
|
13
13
|
|
14
14
|
|
15
15
|
class LsRestClientMocker(object):
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
def __init__(self):
|
17
|
+
super().__init__()
|
18
|
+
self.mocks = {}
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
client.mock(mock_name, mock)
|
24
|
-
self.mocks[mock_name] = LsRestClientMockModel(client=client, mock_name=mock_name, mock=mock)
|
25
|
-
return mock
|
20
|
+
def mock(self, client: LsRestClient | str, method: str, url: str, *args, **kwargs):
|
21
|
+
if isinstance(client, str):
|
22
|
+
client = LsRestClient.client(client)
|
26
23
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
31
29
|
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
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 = {}
|
34
|
+
|
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]
|
37
40
|
|
38
41
|
|
39
42
|
@contextmanager
|
40
43
|
def lsrestclient_mock_context():
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
+
mocker = LsRestClientMocker()
|
45
|
+
yield mocker
|
46
|
+
mocker.unmock_all()
|
@@ -1,13 +1,13 @@
|
|
1
1
|
lsrestclient/__init__.py,sha256=lI62SHmG0m-iukB5UEwdN5dO4cKnDasOt-TmR1rgaWI,72
|
2
|
-
lsrestclient/auth.py,sha256
|
2
|
+
lsrestclient/auth.py,sha256=n9f5GkKDbzin2jHNv9D7QBb6ZLEjamfbkzzlGpNdjLE,468
|
3
3
|
lsrestclient/client.py,sha256=cQXgRZ7oktHR7u8i9sib9FhBV5JxdmA-QOz6UGkYzUc,9922
|
4
4
|
lsrestclient/contexts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
5
5
|
lsrestclient/contexts/bearer_token.py,sha256=GZZOzAI2Ng_9DvFCbhv1Wwb8wJ1AYCca3fQeNtt2NaU,753
|
6
|
-
lsrestclient/exceptions.py,sha256=
|
6
|
+
lsrestclient/exceptions.py,sha256=Ze_UZutdTxmKXq8brvciZclUIkEGpmFrybPzk6TVk4Q,2105
|
7
7
|
lsrestclient/fixtures.py,sha256=dFkAYQXL6xqTOwRofb03Nsu_cIjq1sG10Rh8dxWfz9s,239
|
8
|
-
lsrestclient/mock.py,sha256=
|
8
|
+
lsrestclient/mock.py,sha256=YanA_CQdaIMd99VkHaWDv3ro59fjBJsNUTZb14rC5aE,1213
|
9
9
|
lsrestclient/response.py,sha256=IXjIgb7ySF-1FdAtnOKRyF3k9LJRB3OFyzIIZI1GNxM,1816
|
10
|
-
lsrestclient-1.3.
|
11
|
-
lsrestclient-1.3.
|
12
|
-
lsrestclient-1.3.
|
13
|
-
lsrestclient-1.3.
|
10
|
+
lsrestclient-1.3.2.dist-info/METADATA,sha256=x5C7teRjs6eW2uHkRrCQjySg9Db1KIeS1dQmB7y88Dc,6656
|
11
|
+
lsrestclient-1.3.2.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
|
12
|
+
lsrestclient-1.3.2.dist-info/entry_points.txt,sha256=7lN1XN3lq5Jv5PlpOdIlFrLlFlwzE5MaEWSgMhKASOM,47
|
13
|
+
lsrestclient-1.3.2.dist-info/RECORD,,
|
File without changes
|
File without changes
|