lsrestclient 2.1.0__py3-none-any.whl → 3.0.1__py3-none-any.whl

Sign up to get free protection for your applications and to get access to all the features.
lsrestclient/auth.py CHANGED
@@ -2,7 +2,7 @@ from lsrestclient import LsRestClient, DownStreamError
2
2
 
3
3
 
4
4
  def auth_am_login(**kwargs) -> str:
5
- am = LsRestClient.from_env("AM_BASE_URL", "am", True)
5
+ am = LsRestClient.from_env("AM_API_URL", "am", True)
6
6
  r = am.post("/auth/login", body=kwargs)
7
7
  if r.status_code == 200:
8
8
  return r.json().get("access_token")
lsrestclient/client.py CHANGED
@@ -56,6 +56,9 @@ class LsRestClient(Session):
56
56
  except KeyError:
57
57
  raise Exception(f"LsRestClient with name '{name}' not initialized.")
58
58
 
59
+ def __repr__(self):
60
+ return f"<LsRestClient name:'{self.name}' base_url:'{self.base_url}'>"
61
+
59
62
  def __init__(
60
63
  self,
61
64
  base_url: str = None,
@@ -95,7 +98,7 @@ class LsRestClient(Session):
95
98
 
96
99
  :param url: The relative URL to be used to build the full URL.
97
100
  :param params: An optional dictionary that contains the parameters to be used in formatting the URL.
98
- Default is None. Used parameters get removed from the dictionary.
101
+ Default is None. Used parameters get removed from the dictionary.
99
102
  :return: The full URL with the parameters replaced.
100
103
  """
101
104
 
@@ -174,6 +177,16 @@ class LsRestClient(Session):
174
177
  if body is not None:
175
178
  kwargs["data"] = lsjsonclasses.LSoftJSONEncoder.dumps(body).encode("utf8")
176
179
 
180
+ return self.real_request(method, url, *args, params=params, **kwargs)
181
+
182
+ def real_request(
183
+ self,
184
+ method: str,
185
+ url: str,
186
+ *args,
187
+ params: Optional[Dict[str, Any]] = None,
188
+ **kwargs,
189
+ ):
177
190
  full_url = self.full_url(url, params)
178
191
 
179
192
  try:
@@ -199,6 +212,7 @@ class LsRestClient(Session):
199
212
  :param kwargs: Additional keyword arguments for the request.
200
213
  :return: The response object of type LsRestClientResponse.
201
214
  """
215
+
202
216
  return self.caller("GET", *args, **kwargs)
203
217
 
204
218
  def post(self, *args, **kwargs) -> LsRestClientResponse:
@@ -278,17 +292,13 @@ class LsRestClientTestClient(LsRestClient):
278
292
  super().__init__(base_url=None, name=name)
279
293
  self.test_client = test_client
280
294
 
281
- def request(
295
+ def real_request(
282
296
  self,
283
297
  method: str,
284
298
  url: str,
285
299
  *args,
286
300
  params: Optional[Dict[str, Any]] = None,
287
- body: Optional[Dict[str, Any]] = None,
288
301
  **kwargs,
289
- ) -> LsRestClientResponse:
290
- if body is not None:
291
- kwargs["data"] = lsjsonclasses.LSoftJSONEncoder.dumps(body).encode("utf8")
292
-
302
+ ):
293
303
  r = self.test_client.request(method, url, *args, params=params, **kwargs)
294
304
  return LsRestClientResponse(status_code=r.status_code, content=r.content.decode("utf8"), headers=r.headers)
@@ -54,20 +54,20 @@ def raise_errors(r, exceptions: Optional[List[Type[Exception]]] = None):
54
54
  else:
55
55
  try:
56
56
  json = r.json()
57
- detail = pydash.get(json, "detail", json)
58
- error_class = pydash.get(detail, "error_class", None)
59
- if error_class is not None:
60
- payload = pydash.get(detail, "error_payload", {})
61
- else:
62
- error_class = pydash.get(detail, "ERROR_CLASS", None)
63
- payload = {}
64
-
65
- if error_class in exceptions_by_class:
66
- e = exceptions_by_class[error_class](**payload)
67
- raise e
68
- # backend errors
69
- raise WebException(status_code=r.status_code, detail=detail)
70
-
71
57
  except Exception as e:
72
58
  log.error(r.content)
73
59
  raise WebException(status_code=r.status_code, detail=r.content)
60
+
61
+ detail = pydash.get(json, "detail", json)
62
+ error_class = pydash.get(detail, "error_class", None)
63
+ if error_class is not None:
64
+ payload = pydash.get(detail, "error_payload", {})
65
+ else:
66
+ error_class = pydash.get(detail, "ERROR_CLASS", None)
67
+ payload = {}
68
+
69
+ if error_class in exceptions_by_class:
70
+ e = exceptions_by_class[error_class](**payload)
71
+ raise e
72
+ # backend errors
73
+ raise WebException(status_code=r.status_code, detail=detail)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lsrestclient
3
- Version: 2.1.0
3
+ Version: 3.0.1
4
4
  Summary: REST Api Client
5
5
  Author: mba
6
6
  Author-email: bartel@electronic-shop.lu
@@ -1,13 +1,13 @@
1
1
  lsrestclient/__init__.py,sha256=lI62SHmG0m-iukB5UEwdN5dO4cKnDasOt-TmR1rgaWI,72
2
- lsrestclient/auth.py,sha256=n9f5GkKDbzin2jHNv9D7QBb6ZLEjamfbkzzlGpNdjLE,468
3
- lsrestclient/client.py,sha256=44fUG8VOKkZIZM8d5EhqVE4rMmq32vLu_9yYXZWcHNg,11159
2
+ lsrestclient/auth.py,sha256=IC6niEht-xB_wC7da0HIeM05Ha785qhls-Q39P6dMHQ,467
3
+ lsrestclient/client.py,sha256=JWhf9foS-2RC0_LZz-DoXD6CE7T-o2J-DuAtDE6aaXc,11336
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=IkIk9bLUHv_Ds9oJ24fbdpdP2nnoUQM5RGX25hzQSdI,2197
6
+ lsrestclient/exceptions.py,sha256=exJd1BfygNkkAqekmWepVXvXlMiOInVzPRnq7TmPURs,2149
7
7
  lsrestclient/fixtures.py,sha256=dFkAYQXL6xqTOwRofb03Nsu_cIjq1sG10Rh8dxWfz9s,239
8
8
  lsrestclient/mock.py,sha256=Ya12F0t5sXHTSt-X4jDDj5ILJx6y6QaBAMXutQMsIRI,1376
9
9
  lsrestclient/response.py,sha256=zVisLH4TMG5Ww9gseLSb1rVpHUESoR03DNpL0bv1GCU,2165
10
- lsrestclient-2.1.0.dist-info/METADATA,sha256=repSCR3U_52T6EStuuR2IY2Sx02ZNf1BXVZlLjJTShM,6748
11
- lsrestclient-2.1.0.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
12
- lsrestclient-2.1.0.dist-info/entry_points.txt,sha256=7lN1XN3lq5Jv5PlpOdIlFrLlFlwzE5MaEWSgMhKASOM,47
13
- lsrestclient-2.1.0.dist-info/RECORD,,
10
+ lsrestclient-3.0.1.dist-info/METADATA,sha256=-b5iizfnj9RQQXa4HFIzhI_RpIEjy9z88CnIEACx4P4,6748
11
+ lsrestclient-3.0.1.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
12
+ lsrestclient-3.0.1.dist-info/entry_points.txt,sha256=7lN1XN3lq5Jv5PlpOdIlFrLlFlwzE5MaEWSgMhKASOM,47
13
+ lsrestclient-3.0.1.dist-info/RECORD,,