Compare commits
7 Commits
Author | SHA1 | Date | |
---|---|---|---|
dca2466e25 | |||
f24d664c62 | |||
e9de91a02e | |||
e25f636ebc | |||
1a9ddbe93e | |||
3e49e5adbd | |||
92bd17ce30 |
@ -1,5 +1,11 @@
|
|||||||
# UTE API Wrapper 🇺🇾
|
# UTE API Wrapper 🇺🇾
|
||||||
|
|
||||||
|
# THIS API NO LONGER WORKS
|
||||||
|
|
||||||
|
UTE deprecated the API that this wrapper uses on April 15th 2024. More information [here](https://github.com/rogsme/ute_homeassistant_integration/issues/3#issuecomment-2054332575).
|
||||||
|
|
||||||
|
I'll archive this repository in a few days.
|
||||||
|
|
||||||
<p align="center">
|
<p align="center">
|
||||||
<img src="https://gitlab.com/uploads/-/system/project/avatar/48558040/icon.png" alt="ute-wrapper"/>
|
<img src="https://gitlab.com/uploads/-/system/project/avatar/48558040/icon.png" alt="ute-wrapper"/>
|
||||||
</p>
|
</p>
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
[tool.poetry]
|
[tool.poetry]
|
||||||
name = "ute-wrapper"
|
name = "ute-wrapper"
|
||||||
version = "2.3.1"
|
version = "2.5.1"
|
||||||
description = "A wrapper to interact with UTE's API"
|
description = "[DEPRECATED] A wrapper to interact with UTE's API"
|
||||||
authors = ["Roger Gonzalez <roger@rogs.me>"]
|
authors = ["Roger Gonzalez <roger@rogs.me>"]
|
||||||
license = "GPL-3.0-or-later"
|
license = "GPL-3.0-or-later"
|
||||||
readme = "README.md"
|
readme = "README.md"
|
||||||
|
@ -112,7 +112,7 @@ class UTEClient:
|
|||||||
delay: float = 2,
|
delay: float = 2,
|
||||||
) -> requests.Response:
|
) -> requests.Response:
|
||||||
"""
|
"""
|
||||||
Make a HTTP request with retries.
|
Make a HTTP request with retries and handle expired authorization.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
method (str): The HTTP method to use. Accepted methods are ``GET``, ``POST``.
|
method (str): The HTTP method to use. Accepted methods are ``GET``, ``POST``.
|
||||||
@ -134,12 +134,15 @@ class UTEClient:
|
|||||||
"Connection": "Keep-Alive",
|
"Connection": "Keep-Alive",
|
||||||
}
|
}
|
||||||
|
|
||||||
if self.authorization:
|
|
||||||
headers["Authorization"] = f"Bearer {self.authorization}"
|
|
||||||
|
|
||||||
for attempt in range(retries):
|
for attempt in range(retries):
|
||||||
|
if self.authorization:
|
||||||
|
headers["Authorization"] = f"Bearer {self.authorization}"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
response = getattr(requests, method.lower(), self._method_not_supported)(url, headers=headers, json=data)
|
response = getattr(requests, method.lower(), self._method_not_supported)(url, headers=headers, json=data)
|
||||||
|
if response.status_code == requests.codes.unauthorized:
|
||||||
|
self._login()
|
||||||
|
continue
|
||||||
response.raise_for_status()
|
response.raise_for_status()
|
||||||
return response
|
return response
|
||||||
except (requests.RequestException, Exception):
|
except (requests.RequestException, Exception):
|
||||||
|
@ -50,6 +50,18 @@ def test_make_request_no_authorization(ute_client, mocker: MockerFixture):
|
|||||||
assert response.json()["success"] is True
|
assert response.json()["success"] is True
|
||||||
|
|
||||||
|
|
||||||
|
def test_make_request_expired_authorization(ute_client, mocker: MockerFixture):
|
||||||
|
"""Test the _make_request method when the authorization code has expired."""
|
||||||
|
mocked_unauthorized_response = mocker.Mock(status_code=requests.codes.unauthorized)
|
||||||
|
mocked_success_response = mocker.Mock(status_code=requests.codes.ok, json=lambda: {"success": True})
|
||||||
|
mocker.patch("requests.get", side_effect=[mocked_unauthorized_response, mocked_success_response])
|
||||||
|
mocker.patch.object(ute_client, "_login")
|
||||||
|
response = ute_client._make_request("GET", "http://example.com")
|
||||||
|
assert response.status_code == requests.codes.ok
|
||||||
|
assert response.json()["success"] is True
|
||||||
|
ute_client._login.assert_called_once()
|
||||||
|
|
||||||
|
|
||||||
def test_make_request_all_retries_failed(ute_client, mocker: MockerFixture):
|
def test_make_request_all_retries_failed(ute_client, mocker: MockerFixture):
|
||||||
"""Test the _make_request method when all retries fail."""
|
"""Test the _make_request method when all retries fail."""
|
||||||
mocked_response = mocker.Mock()
|
mocked_response = mocker.Mock()
|
||||||
|
Reference in New Issue
Block a user