lsrestclient 3.1.0__py3-none-any.whl → 3.2.2__py3-none-any.whl

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/client.py CHANGED
@@ -64,13 +64,13 @@ class LsRestClient(Session):
64
64
  base_url: str = None,
65
65
  name: str = "default",
66
66
  headers: dict = None,
67
- ignore_bearer_token: bool = False,
67
+ ignore_bearer_context: bool = False,
68
68
  ) -> None:
69
69
  """Class representing a REST client for JSON API."""
70
70
 
71
71
  self._mocks = {}
72
72
  self.base_url = base_url
73
- self.ignore_bearer_token = ignore_bearer_token
73
+ self.ignore_bearer_context = ignore_bearer_context
74
74
  self.base_headers = {"content-type": "application/json"}
75
75
 
76
76
  with bearer_token_context() as bearer_token:
@@ -174,7 +174,7 @@ class LsRestClient(Session):
174
174
  with bearer_token_context() as bearer_token:
175
175
  bearer_headers = (
176
176
  {"Authorization": f"Bearer {bearer_token}"}
177
- if bearer_token is not None and not self.ignore_bearer_token
177
+ if bearer_token is not None and not self.ignore_bearer_context
178
178
  else {}
179
179
  )
180
180
 
@@ -314,3 +314,4 @@ class LsRestClientTestClient(LsRestClient):
314
314
  ):
315
315
  r = self.test_client.request(method, url, *args, params=params, **kwargs)
316
316
  return LsRestClientResponse(status_code=r.status_code, content=r.content.decode("utf8"), headers=r.headers)
317
+
@@ -0,0 +1,40 @@
1
+ from abc import ABC, abstractmethod
2
+
3
+ from lsrestclient import LsRestClient
4
+ import logging
5
+
6
+ log = logging.getLogger(__name__)
7
+
8
+
9
+ class LsFastApiClientBase(ABC):
10
+ _client = None
11
+ client_name = None
12
+
13
+ def __init__(self):
14
+ pass
15
+
16
+ @classmethod
17
+ def client(cls) -> LsRestClient:
18
+ # noinspection PyBroadException
19
+ try:
20
+ cls._client = LsRestClient.client(cls.client_name)
21
+ except Exception as e: # pragma: no cover
22
+ # noinspection PyArgumentList
23
+ cls._client = cls.register()
24
+ return cls._client
25
+
26
+ @classmethod
27
+ def register(cls, base_url: str = None) -> LsRestClient:
28
+ # noinspection PyArgumentList
29
+ log.debug(f"Registering {cls.client_name} API client at {base_url}")
30
+ cls._client = LsRestClient(name=cls.client_name, base_url=base_url or cls.base_url())
31
+ return cls._client
32
+
33
+ @classmethod
34
+ def health(cls):
35
+ return cls.client().get("/healthz")
36
+
37
+ @classmethod
38
+ @abstractmethod
39
+ def base_url(cls):
40
+ raise NotImplementedError
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: lsrestclient
3
- Version: 3.1.0
3
+ Version: 3.2.2
4
4
  Summary: REST Api Client
5
5
  Author: mba
6
6
  Author-email: bartel@electronic-shop.lu
@@ -1,13 +1,14 @@
1
1
  lsrestclient/__init__.py,sha256=lI62SHmG0m-iukB5UEwdN5dO4cKnDasOt-TmR1rgaWI,72
2
2
  lsrestclient/auth.py,sha256=IC6niEht-xB_wC7da0HIeM05Ha785qhls-Q39P6dMHQ,467
3
- lsrestclient/client.py,sha256=dYdfQhPnvblJTg0SAmcljQraASuoEyVcLSDYD9RKSjc,11854
3
+ lsrestclient/client.py,sha256=9OOKYB4HqCeRsiZaS0iVwH5G23S7sG93gNdlT89l1xk,11863
4
4
  lsrestclient/contexts/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
5
5
  lsrestclient/contexts/bearer_token.py,sha256=GZZOzAI2Ng_9DvFCbhv1Wwb8wJ1AYCca3fQeNtt2NaU,753
6
6
  lsrestclient/exceptions.py,sha256=exJd1BfygNkkAqekmWepVXvXlMiOInVzPRnq7TmPURs,2149
7
7
  lsrestclient/fixtures.py,sha256=dFkAYQXL6xqTOwRofb03Nsu_cIjq1sG10Rh8dxWfz9s,239
8
+ lsrestclient/lsfastapi.py,sha256=AkeJI4zcJTYGgj625OY_ae_aFi9BBiZP6xy85NxJXJ8,1064
8
9
  lsrestclient/mock.py,sha256=Ya12F0t5sXHTSt-X4jDDj5ILJx6y6QaBAMXutQMsIRI,1376
9
10
  lsrestclient/response.py,sha256=8ovVmVB8gLW3U1EkewdQlPdFYP-YLoOpIH3ATVQc3wc,2189
10
- lsrestclient-3.1.0.dist-info/METADATA,sha256=bX3k1GwgD-a_QgsbEpEAHdeY-0Vejny_s_sFOI6w6sw,6748
11
- lsrestclient-3.1.0.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
12
- lsrestclient-3.1.0.dist-info/entry_points.txt,sha256=7lN1XN3lq5Jv5PlpOdIlFrLlFlwzE5MaEWSgMhKASOM,47
13
- lsrestclient-3.1.0.dist-info/RECORD,,
11
+ lsrestclient-3.2.2.dist-info/METADATA,sha256=uXItwT6i30ZmxxTBtjcqnrbg8WV6NIvIRkcOiFuQCRQ,6748
12
+ lsrestclient-3.2.2.dist-info/WHEEL,sha256=7Z8_27uaHI_UZAc4Uox4PpBhQ9Y5_modZXWMxtUi4NU,88
13
+ lsrestclient-3.2.2.dist-info/entry_points.txt,sha256=7lN1XN3lq5Jv5PlpOdIlFrLlFlwzE5MaEWSgMhKASOM,47
14
+ lsrestclient-3.2.2.dist-info/RECORD,,