lynkora-sdk-python 0.1.0__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.
- lynkora_sdk_python-0.1.0/LICENSE +21 -0
- lynkora_sdk_python-0.1.0/PKG-INFO +72 -0
- lynkora_sdk_python-0.1.0/README.md +54 -0
- lynkora_sdk_python-0.1.0/lynkora_sdk/__init__.py +4 -0
- lynkora_sdk_python-0.1.0/lynkora_sdk/client.py +78 -0
- lynkora_sdk_python-0.1.0/lynkora_sdk/errors.py +5 -0
- lynkora_sdk_python-0.1.0/lynkora_sdk_python.egg-info/PKG-INFO +72 -0
- lynkora_sdk_python-0.1.0/lynkora_sdk_python.egg-info/SOURCES.txt +13 -0
- lynkora_sdk_python-0.1.0/lynkora_sdk_python.egg-info/dependency_links.txt +1 -0
- lynkora_sdk_python-0.1.0/lynkora_sdk_python.egg-info/requires.txt +5 -0
- lynkora_sdk_python-0.1.0/lynkora_sdk_python.egg-info/top_level.txt +1 -0
- lynkora_sdk_python-0.1.0/pyproject.toml +25 -0
- lynkora_sdk_python-0.1.0/setup.cfg +4 -0
- lynkora_sdk_python-0.1.0/tests/test_client.py +100 -0
- lynkora_sdk_python-0.1.0/tests/test_errors.py +10 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Lynkora
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: lynkora-sdk-python
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: SDK Python para integração com a API de Actions/Subscribers do Lynkora Admin Service.
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Project-URL: Homepage, https://docs.lynkora.dev/docs/para-desenvolvedores/sdks
|
|
7
|
+
Project-URL: Repository, https://github.com/natanaeldeveloper/lynkora-api
|
|
8
|
+
Project-URL: Issues, https://github.com/natanaeldeveloper/lynkora-api/issues
|
|
9
|
+
Keywords: lynkora,billing,usage-based-billing,metering,sdk
|
|
10
|
+
Requires-Python: >=3.9
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Provides-Extra: dev
|
|
14
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
15
|
+
Requires-Dist: build>=1.0; extra == "dev"
|
|
16
|
+
Requires-Dist: twine>=5.0; extra == "dev"
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
|
|
19
|
+
# lynkora-sdk-python
|
|
20
|
+
|
|
21
|
+
SDK Python pra integrar com a API pública do Lynkora — registrar assinantes e
|
|
22
|
+
controlar consumo (reservar, confirmar, cancelar). Zero dependências de
|
|
23
|
+
runtime (usa `urllib.request` da biblioteca padrão), cliente síncrono.
|
|
24
|
+
|
|
25
|
+
Documentação completa dos endpoints: [docs.lynkora.dev/docs/para-desenvolvedores/sdks](https://docs.lynkora.dev/docs/para-desenvolvedores/sdks).
|
|
26
|
+
|
|
27
|
+
## Instalação
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pip install lynkora-sdk-python
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Uso
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
import os
|
|
37
|
+
from lynkora_sdk import LynkoraClient
|
|
38
|
+
|
|
39
|
+
lynkora = LynkoraClient(
|
|
40
|
+
api_key=os.environ["LYNKORA_API_KEY"],
|
|
41
|
+
base_url="https://api.lynkora.dev",
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
result = lynkora.consume_action(
|
|
45
|
+
subscriber_id="sub_123",
|
|
46
|
+
action_slug="generate-report",
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
lynkora.confirm_consumption(result["reservationId"])
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Erros da API chegam como `LynkoraApiError`, com `status_code`, a mensagem (via
|
|
53
|
+
`str(err)`) e o corpo original da resposta em `body`:
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
from lynkora_sdk import LynkoraApiError
|
|
57
|
+
|
|
58
|
+
try:
|
|
59
|
+
lynkora.consume_action(subscriber_id="sub_123", action_slug="generate-report")
|
|
60
|
+
except LynkoraApiError as err:
|
|
61
|
+
print(err.status_code, str(err), err.body)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Escopo
|
|
65
|
+
|
|
66
|
+
Só os 4 endpoints autenticados por `X-Api-Key`: `consume_action`,
|
|
67
|
+
`confirm_consumption`, `cancel_consumption` e `register_subscriber`. Nada de
|
|
68
|
+
painel administrativo nem cobrança — isso é feito direto pela API.
|
|
69
|
+
|
|
70
|
+
## Licença
|
|
71
|
+
|
|
72
|
+
MIT
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# lynkora-sdk-python
|
|
2
|
+
|
|
3
|
+
SDK Python pra integrar com a API pública do Lynkora — registrar assinantes e
|
|
4
|
+
controlar consumo (reservar, confirmar, cancelar). Zero dependências de
|
|
5
|
+
runtime (usa `urllib.request` da biblioteca padrão), cliente síncrono.
|
|
6
|
+
|
|
7
|
+
Documentação completa dos endpoints: [docs.lynkora.dev/docs/para-desenvolvedores/sdks](https://docs.lynkora.dev/docs/para-desenvolvedores/sdks).
|
|
8
|
+
|
|
9
|
+
## Instalação
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install lynkora-sdk-python
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Uso
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
import os
|
|
19
|
+
from lynkora_sdk import LynkoraClient
|
|
20
|
+
|
|
21
|
+
lynkora = LynkoraClient(
|
|
22
|
+
api_key=os.environ["LYNKORA_API_KEY"],
|
|
23
|
+
base_url="https://api.lynkora.dev",
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
result = lynkora.consume_action(
|
|
27
|
+
subscriber_id="sub_123",
|
|
28
|
+
action_slug="generate-report",
|
|
29
|
+
)
|
|
30
|
+
|
|
31
|
+
lynkora.confirm_consumption(result["reservationId"])
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
Erros da API chegam como `LynkoraApiError`, com `status_code`, a mensagem (via
|
|
35
|
+
`str(err)`) e o corpo original da resposta em `body`:
|
|
36
|
+
|
|
37
|
+
```python
|
|
38
|
+
from lynkora_sdk import LynkoraApiError
|
|
39
|
+
|
|
40
|
+
try:
|
|
41
|
+
lynkora.consume_action(subscriber_id="sub_123", action_slug="generate-report")
|
|
42
|
+
except LynkoraApiError as err:
|
|
43
|
+
print(err.status_code, str(err), err.body)
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Escopo
|
|
47
|
+
|
|
48
|
+
Só os 4 endpoints autenticados por `X-Api-Key`: `consume_action`,
|
|
49
|
+
`confirm_consumption`, `cancel_consumption` e `register_subscriber`. Nada de
|
|
50
|
+
painel administrativo nem cobrança — isso é feito direto pela API.
|
|
51
|
+
|
|
52
|
+
## Licença
|
|
53
|
+
|
|
54
|
+
MIT
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import json
|
|
2
|
+
from urllib.error import HTTPError
|
|
3
|
+
from urllib.request import Request, urlopen
|
|
4
|
+
|
|
5
|
+
from .errors import LynkoraApiError
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class LynkoraClient:
|
|
9
|
+
def __init__(self, api_key: str, base_url: str) -> None:
|
|
10
|
+
self._api_key = api_key
|
|
11
|
+
self._base_url = base_url
|
|
12
|
+
|
|
13
|
+
def register_subscriber(
|
|
14
|
+
self,
|
|
15
|
+
suite_id: str,
|
|
16
|
+
name: str,
|
|
17
|
+
email: str,
|
|
18
|
+
document: str | None = None,
|
|
19
|
+
metadata: dict | None = None,
|
|
20
|
+
) -> dict:
|
|
21
|
+
body = {"name": name, "email": email}
|
|
22
|
+
if document is not None:
|
|
23
|
+
body["document"] = document
|
|
24
|
+
if metadata is not None:
|
|
25
|
+
body["metadata"] = metadata
|
|
26
|
+
return self._request(
|
|
27
|
+
"POST", f"/v1/suites/{suite_id}/subscribers/register", body
|
|
28
|
+
)
|
|
29
|
+
|
|
30
|
+
def consume_action(
|
|
31
|
+
self,
|
|
32
|
+
subscriber_id: str,
|
|
33
|
+
action_slug: str,
|
|
34
|
+
quantity: int | None = None,
|
|
35
|
+
metadata: dict | None = None,
|
|
36
|
+
) -> dict:
|
|
37
|
+
body = {"subscriberId": subscriber_id, "actionSlug": action_slug}
|
|
38
|
+
if quantity is not None:
|
|
39
|
+
body["quantity"] = quantity
|
|
40
|
+
if metadata is not None:
|
|
41
|
+
body["metadata"] = metadata
|
|
42
|
+
return self._request("POST", "/v1/actions/consume", body)
|
|
43
|
+
|
|
44
|
+
def confirm_consumption(self, reservation_id: str) -> dict:
|
|
45
|
+
return self._request("POST", f"/v1/actions/confirm/{reservation_id}")
|
|
46
|
+
|
|
47
|
+
def cancel_consumption(self, reservation_id: str) -> None:
|
|
48
|
+
return self._request("POST", f"/v1/actions/cancel/{reservation_id}")
|
|
49
|
+
|
|
50
|
+
def _request(self, method: str, path: str, body: dict | None = None) -> object:
|
|
51
|
+
data = json.dumps(body).encode("utf-8") if body is not None else None
|
|
52
|
+
req = Request(
|
|
53
|
+
f"{self._base_url}{path}",
|
|
54
|
+
data=data,
|
|
55
|
+
method=method,
|
|
56
|
+
headers={
|
|
57
|
+
"X-Api-Key": self._api_key,
|
|
58
|
+
"Content-Type": "application/json",
|
|
59
|
+
},
|
|
60
|
+
)
|
|
61
|
+
|
|
62
|
+
try:
|
|
63
|
+
with urlopen(req) as response:
|
|
64
|
+
if response.status == 204:
|
|
65
|
+
return None
|
|
66
|
+
return json.loads(response.read())
|
|
67
|
+
except HTTPError as e:
|
|
68
|
+
raw = e.read()
|
|
69
|
+
try:
|
|
70
|
+
error_body = json.loads(raw) if raw else None
|
|
71
|
+
except ValueError:
|
|
72
|
+
error_body = None
|
|
73
|
+
message = (
|
|
74
|
+
error_body.get("message")
|
|
75
|
+
if isinstance(error_body, dict) and error_body.get("message")
|
|
76
|
+
else e.reason
|
|
77
|
+
)
|
|
78
|
+
raise LynkoraApiError(e.code, message, error_body) from e
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: lynkora-sdk-python
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: SDK Python para integração com a API de Actions/Subscribers do Lynkora Admin Service.
|
|
5
|
+
License-Expression: MIT
|
|
6
|
+
Project-URL: Homepage, https://docs.lynkora.dev/docs/para-desenvolvedores/sdks
|
|
7
|
+
Project-URL: Repository, https://github.com/natanaeldeveloper/lynkora-api
|
|
8
|
+
Project-URL: Issues, https://github.com/natanaeldeveloper/lynkora-api/issues
|
|
9
|
+
Keywords: lynkora,billing,usage-based-billing,metering,sdk
|
|
10
|
+
Requires-Python: >=3.9
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Provides-Extra: dev
|
|
14
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
15
|
+
Requires-Dist: build>=1.0; extra == "dev"
|
|
16
|
+
Requires-Dist: twine>=5.0; extra == "dev"
|
|
17
|
+
Dynamic: license-file
|
|
18
|
+
|
|
19
|
+
# lynkora-sdk-python
|
|
20
|
+
|
|
21
|
+
SDK Python pra integrar com a API pública do Lynkora — registrar assinantes e
|
|
22
|
+
controlar consumo (reservar, confirmar, cancelar). Zero dependências de
|
|
23
|
+
runtime (usa `urllib.request` da biblioteca padrão), cliente síncrono.
|
|
24
|
+
|
|
25
|
+
Documentação completa dos endpoints: [docs.lynkora.dev/docs/para-desenvolvedores/sdks](https://docs.lynkora.dev/docs/para-desenvolvedores/sdks).
|
|
26
|
+
|
|
27
|
+
## Instalação
|
|
28
|
+
|
|
29
|
+
```bash
|
|
30
|
+
pip install lynkora-sdk-python
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
## Uso
|
|
34
|
+
|
|
35
|
+
```python
|
|
36
|
+
import os
|
|
37
|
+
from lynkora_sdk import LynkoraClient
|
|
38
|
+
|
|
39
|
+
lynkora = LynkoraClient(
|
|
40
|
+
api_key=os.environ["LYNKORA_API_KEY"],
|
|
41
|
+
base_url="https://api.lynkora.dev",
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
result = lynkora.consume_action(
|
|
45
|
+
subscriber_id="sub_123",
|
|
46
|
+
action_slug="generate-report",
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
lynkora.confirm_consumption(result["reservationId"])
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
Erros da API chegam como `LynkoraApiError`, com `status_code`, a mensagem (via
|
|
53
|
+
`str(err)`) e o corpo original da resposta em `body`:
|
|
54
|
+
|
|
55
|
+
```python
|
|
56
|
+
from lynkora_sdk import LynkoraApiError
|
|
57
|
+
|
|
58
|
+
try:
|
|
59
|
+
lynkora.consume_action(subscriber_id="sub_123", action_slug="generate-report")
|
|
60
|
+
except LynkoraApiError as err:
|
|
61
|
+
print(err.status_code, str(err), err.body)
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
## Escopo
|
|
65
|
+
|
|
66
|
+
Só os 4 endpoints autenticados por `X-Api-Key`: `consume_action`,
|
|
67
|
+
`confirm_consumption`, `cancel_consumption` e `register_subscriber`. Nada de
|
|
68
|
+
painel administrativo nem cobrança — isso é feito direto pela API.
|
|
69
|
+
|
|
70
|
+
## Licença
|
|
71
|
+
|
|
72
|
+
MIT
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
lynkora_sdk/__init__.py
|
|
5
|
+
lynkora_sdk/client.py
|
|
6
|
+
lynkora_sdk/errors.py
|
|
7
|
+
lynkora_sdk_python.egg-info/PKG-INFO
|
|
8
|
+
lynkora_sdk_python.egg-info/SOURCES.txt
|
|
9
|
+
lynkora_sdk_python.egg-info/dependency_links.txt
|
|
10
|
+
lynkora_sdk_python.egg-info/requires.txt
|
|
11
|
+
lynkora_sdk_python.egg-info/top_level.txt
|
|
12
|
+
tests/test_client.py
|
|
13
|
+
tests/test_errors.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
lynkora_sdk
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "lynkora-sdk-python"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "SDK Python para integração com a API de Actions/Subscribers do Lynkora Admin Service."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.9"
|
|
7
|
+
license = "MIT"
|
|
8
|
+
license-files = ["LICENSE"]
|
|
9
|
+
keywords = ["lynkora", "billing", "usage-based-billing", "metering", "sdk"]
|
|
10
|
+
dependencies = []
|
|
11
|
+
|
|
12
|
+
[project.urls]
|
|
13
|
+
Homepage = "https://docs.lynkora.dev/docs/para-desenvolvedores/sdks"
|
|
14
|
+
Repository = "https://github.com/natanaeldeveloper/lynkora-api"
|
|
15
|
+
Issues = "https://github.com/natanaeldeveloper/lynkora-api/issues"
|
|
16
|
+
|
|
17
|
+
[project.optional-dependencies]
|
|
18
|
+
dev = ["pytest>=8.0", "build>=1.0", "twine>=5.0"]
|
|
19
|
+
|
|
20
|
+
[build-system]
|
|
21
|
+
requires = ["setuptools>=68"]
|
|
22
|
+
build-backend = "setuptools.build_meta"
|
|
23
|
+
|
|
24
|
+
[tool.setuptools.packages.find]
|
|
25
|
+
include = ["lynkora_sdk*"]
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
from io import BytesIO
|
|
2
|
+
from unittest.mock import patch
|
|
3
|
+
from urllib.error import HTTPError, URLError
|
|
4
|
+
|
|
5
|
+
import pytest
|
|
6
|
+
|
|
7
|
+
from lynkora_sdk.client import LynkoraClient
|
|
8
|
+
from lynkora_sdk.errors import LynkoraApiError
|
|
9
|
+
|
|
10
|
+
BASE_URL = "https://admin.example.com"
|
|
11
|
+
API_KEY = "test-api-key"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class FakeResponse:
|
|
15
|
+
def __init__(self, status: int, body: bytes) -> None:
|
|
16
|
+
self.status = status
|
|
17
|
+
self._body = body
|
|
18
|
+
|
|
19
|
+
def read(self) -> bytes:
|
|
20
|
+
return self._body
|
|
21
|
+
|
|
22
|
+
def __enter__(self) -> "FakeResponse":
|
|
23
|
+
return self
|
|
24
|
+
|
|
25
|
+
def __exit__(self, *exc: object) -> None:
|
|
26
|
+
return None
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
@pytest.fixture
|
|
30
|
+
def client() -> LynkoraClient:
|
|
31
|
+
return LynkoraClient(api_key=API_KEY, base_url=BASE_URL)
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def test_register_subscriber_posts_and_returns_body(client: LynkoraClient) -> None:
|
|
35
|
+
fake = FakeResponse(201, b'{"id": "sub-1", "status": "ACTIVE"}')
|
|
36
|
+
with patch("lynkora_sdk.client.urlopen", return_value=fake) as urlopen_mock:
|
|
37
|
+
result = client.register_subscriber(
|
|
38
|
+
suite_id="suite-1", name="Jane Doe", email="jane@example.com"
|
|
39
|
+
)
|
|
40
|
+
|
|
41
|
+
assert result == {"id": "sub-1", "status": "ACTIVE"}
|
|
42
|
+
req = urlopen_mock.call_args[0][0]
|
|
43
|
+
assert req.full_url == f"{BASE_URL}/v1/suites/suite-1/subscribers/register"
|
|
44
|
+
assert req.headers["X-api-key"] == API_KEY
|
|
45
|
+
assert req.data == b'{"name": "Jane Doe", "email": "jane@example.com"}'
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def test_consume_action_posts_and_returns_body(client: LynkoraClient) -> None:
|
|
49
|
+
fake = FakeResponse(201, b'{"reservationId": "res-1", "quantity": 1}')
|
|
50
|
+
with patch("lynkora_sdk.client.urlopen", return_value=fake) as urlopen_mock:
|
|
51
|
+
result = client.consume_action(
|
|
52
|
+
subscriber_id="sub-1", action_slug="sign_document"
|
|
53
|
+
)
|
|
54
|
+
|
|
55
|
+
assert result == {"reservationId": "res-1", "quantity": 1}
|
|
56
|
+
req = urlopen_mock.call_args[0][0]
|
|
57
|
+
assert req.full_url == f"{BASE_URL}/v1/actions/consume"
|
|
58
|
+
assert req.data == b'{"subscriberId": "sub-1", "actionSlug": "sign_document"}'
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def test_confirm_consumption_posts_and_returns_body(client: LynkoraClient) -> None:
|
|
62
|
+
fake = FakeResponse(200, b'{"usageEventId": "usage-1"}')
|
|
63
|
+
with patch("lynkora_sdk.client.urlopen", return_value=fake) as urlopen_mock:
|
|
64
|
+
result = client.confirm_consumption(reservation_id="res-1")
|
|
65
|
+
|
|
66
|
+
assert result == {"usageEventId": "usage-1"}
|
|
67
|
+
req = urlopen_mock.call_args[0][0]
|
|
68
|
+
assert req.full_url == f"{BASE_URL}/v1/actions/confirm/res-1"
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
def test_cancel_consumption_returns_none_for_204(client: LynkoraClient) -> None:
|
|
72
|
+
fake = FakeResponse(204, b"")
|
|
73
|
+
with patch("lynkora_sdk.client.urlopen", return_value=fake) as urlopen_mock:
|
|
74
|
+
result = client.cancel_consumption(reservation_id="res-1")
|
|
75
|
+
|
|
76
|
+
assert result is None
|
|
77
|
+
req = urlopen_mock.call_args[0][0]
|
|
78
|
+
assert req.full_url == f"{BASE_URL}/v1/actions/cancel/res-1"
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
def test_raises_lynkora_api_error_on_non_2xx(client: LynkoraClient) -> None:
|
|
82
|
+
error = HTTPError(
|
|
83
|
+
url=f"{BASE_URL}/v1/actions/consume",
|
|
84
|
+
code=429,
|
|
85
|
+
msg="Too Many Requests",
|
|
86
|
+
hdrs=None,
|
|
87
|
+
fp=BytesIO(b'{"message": "Cota de acoes excedida."}'),
|
|
88
|
+
)
|
|
89
|
+
with patch("lynkora_sdk.client.urlopen", side_effect=error):
|
|
90
|
+
with pytest.raises(LynkoraApiError) as exc_info:
|
|
91
|
+
client.consume_action(subscriber_id="sub-1", action_slug="sign_document")
|
|
92
|
+
|
|
93
|
+
assert exc_info.value.status_code == 429
|
|
94
|
+
assert exc_info.value.body == {"message": "Cota de acoes excedida."}
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def test_network_error_propagates_unwrapped(client: LynkoraClient) -> None:
|
|
98
|
+
with patch("lynkora_sdk.client.urlopen", side_effect=URLError("no route")):
|
|
99
|
+
with pytest.raises(URLError):
|
|
100
|
+
client.consume_action(subscriber_id="sub-1", action_slug="sign_document")
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
from lynkora_sdk.errors import LynkoraApiError
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
def test_exposes_status_code_message_and_body() -> None:
|
|
5
|
+
err = LynkoraApiError(429, "Cota de acoes excedida.", {"message": "Cota de acoes excedida."})
|
|
6
|
+
|
|
7
|
+
assert isinstance(err, Exception)
|
|
8
|
+
assert err.status_code == 429
|
|
9
|
+
assert str(err) == "Cota de acoes excedida."
|
|
10
|
+
assert err.body == {"message": "Cota de acoes excedida."}
|