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.
- {pyescoapi-0.0.15 → pyescoapi-0.0.16}/PKG-INFO +1 -1
- {pyescoapi-0.0.15 → pyescoapi-0.0.16}/pyEscoAPI/esco_api.py +20 -15
- {pyescoapi-0.0.15 → pyescoapi-0.0.16}/pyEscoAPI.egg-info/PKG-INFO +1 -1
- {pyescoapi-0.0.15 → pyescoapi-0.0.16}/pyproject.toml +1 -1
- {pyescoapi-0.0.15 → pyescoapi-0.0.16}/tests/test_client.py +22 -0
- {pyescoapi-0.0.15 → pyescoapi-0.0.16}/README.md +0 -0
- {pyescoapi-0.0.15 → pyescoapi-0.0.16}/pyEscoAPI/__init__.py +0 -0
- {pyescoapi-0.0.15 → pyescoapi-0.0.16}/pyEscoAPI/dataclasses.py +0 -0
- {pyescoapi-0.0.15 → pyescoapi-0.0.16}/pyEscoAPI/exception.py +0 -0
- {pyescoapi-0.0.15 → pyescoapi-0.0.16}/pyEscoAPI.egg-info/SOURCES.txt +0 -0
- {pyescoapi-0.0.15 → pyescoapi-0.0.16}/pyEscoAPI.egg-info/dependency_links.txt +0 -0
- {pyescoapi-0.0.15 → pyescoapi-0.0.16}/pyEscoAPI.egg-info/requires.txt +0 -0
- {pyescoapi-0.0.15 → pyescoapi-0.0.16}/pyEscoAPI.egg-info/top_level.txt +0 -0
- {pyescoapi-0.0.15 → pyescoapi-0.0.16}/setup.cfg +0 -0
|
@@ -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
|
|
115
|
-
cls.
|
|
116
|
-
|
|
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
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
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
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
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
|
-
|
|
146
|
+
self.__esco_login()
|
|
147
|
+
self._initialized = True
|
|
143
148
|
|
|
144
149
|
def get_posiciones(
|
|
145
150
|
self,
|
|
@@ -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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|