pyEscoAPI 0.0.15__tar.gz → 0.0.16__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyEscoAPI
3
- Version: 0.0.15
3
+ Version: 0.0.16
4
4
  Summary: Python client for Esco API (Esco bolsa)
5
5
  Author-email: Codetria <hola@codetria.com>
6
6
  License: MIT License
@@ -34,6 +34,8 @@ class APIVersion(Enum):
34
34
 
35
35
 
36
36
  class EscoAPI:
37
+ _instance = None
38
+
37
39
  base_url: str
38
40
  username: str
39
41
  password: str
@@ -111,17 +113,18 @@ class EscoAPI:
111
113
  self.__esco_login()
112
114
 
113
115
  def __new__(cls, base_url: str, username: str, password: str, client_id: str, version: APIVersion):
114
- if not hasattr(cls, 'instance'):
115
- cls.instance = super(EscoAPI, cls).__new__(cls)
116
- return cls.instance
116
+ if cls._instance is None:
117
+ cls._initialized = False
118
+ cls._instance = super(EscoAPI, cls).__new__(cls)
119
+ return cls._instance
117
120
 
118
121
  def __init__(
119
- self,
120
- base_url: str,
121
- username: str,
122
- password: str,
123
- client_id: str = "",
124
- version: APIVersion = APIVersion.VERSION_9
122
+ self,
123
+ base_url: str,
124
+ username: str,
125
+ password: str,
126
+ client_id: str = "",
127
+ version: APIVersion = APIVersion.VERSION_9
125
128
  ):
126
129
  """
127
130
  Initializes the EscoAPI client, starting a login to the platform.
@@ -133,13 +136,15 @@ class EscoAPI:
133
136
  :param client_id: Optional. Include if you want to specify a client_id.
134
137
  :param version: Optional. The EscoAPI version that you want to use. Default: Version 9.
135
138
  """
136
- self.base_url = f"{base_url}/api/v{version.value}"
137
- self.username = username
138
- self.password = password
139
- self.client_id = client_id
140
- self.version = version
139
+ if not self._initialized:
140
+ self.base_url = f"{base_url}/api/v{version.value}"
141
+ self.username = username
142
+ self.password = password
143
+ self.client_id = client_id
144
+ self.version = version
141
145
 
142
- self.__esco_login()
146
+ self.__esco_login()
147
+ self._initialized = True
143
148
 
144
149
  def get_posiciones(
145
150
  self,
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pyEscoAPI
3
- Version: 0.0.15
3
+ Version: 0.0.16
4
4
  Summary: Python client for Esco API (Esco bolsa)
5
5
  Author-email: Codetria <hola@codetria.com>
6
6
  License: MIT License
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = 'pyEscoAPI'
7
- version = "0.0.15"
7
+ version = "0.0.16"
8
8
  license = {text = "MIT License"}
9
9
  authors = [
10
10
  { name="Codetria", email="hola@codetria.com" },
@@ -2,6 +2,7 @@ import os
2
2
  from datetime import datetime, timedelta
3
3
 
4
4
  import pytest
5
+ from unittest.mock import patch
5
6
 
6
7
  from pyEscoAPI import EscoAPI
7
8
  from pyEscoAPI.esco_api import APIVersion
@@ -18,6 +19,27 @@ def api_client():
18
19
  )
19
20
 
20
21
 
22
+ @patch("pyEscoAPI.esco_api.EscoAPI._EscoAPI__esco_login")
23
+ def test_singleton_should_login_just_once(mock_login):
24
+ client = EscoAPI(
25
+ base_url=os.getenv("base_url"),
26
+ username=os.getenv("user_name"),
27
+ password=os.getenv("password"),
28
+ client_id=os.getenv("client_id"),
29
+ version=APIVersion.VERSION_9
30
+ )
31
+ other_client = EscoAPI(
32
+ base_url=os.getenv("base_url"),
33
+ username=os.getenv("user_name"),
34
+ password=os.getenv("password"),
35
+ client_id=os.getenv("client_id"),
36
+ version=APIVersion.VERSION_9
37
+ )
38
+
39
+ assert client is other_client
40
+ mock_login.assert_called_once()
41
+
42
+
21
43
  def test_get_posiciones(api_client):
22
44
  cuenta = "351008539"
23
45
  result = api_client.get_posiciones(cuenta=cuenta)
File without changes
File without changes