tinyfish 0.5.0__tar.gz → 0.6.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.
- {tinyfish-0.5.0 → tinyfish-0.6.0}/CHANGELOG.md +7 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/PKG-INFO +2 -1
- {tinyfish-0.5.0 → tinyfish-0.6.0}/README.md +1 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/pyproject.toml +1 -1
- {tinyfish-0.5.0 → tinyfish-0.6.0}/src/tinyfish/__init__.py +17 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/src/tinyfish/client.py +5 -0
- tinyfish-0.6.0/src/tinyfish/wallet/__init__.py +41 -0
- tinyfish-0.6.0/src/tinyfish/wallet/types.py +87 -0
- tinyfish-0.6.0/tests/test_wallet.py +239 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/.gitignore +0 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/.pre-commit-config.yaml +0 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/AGENTS.md +0 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/CLAUDE.md +0 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/RELEASE.md +0 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/docs/exceptions-and-errors-guide.md +0 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/docs/internal/api-integration-header.md +0 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/docs/internal/exceptions-and-errors-guide.md +0 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/docs/internal/publishing-private-guide.md +0 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/docs/pagination-guide.md +0 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/docs/proxy-and-browser-profiles.md +0 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/docs/streaming-guide.md +0 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/src/tinyfish/_utils/__init__.py +0 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/src/tinyfish/_utils/client/__init__.py +0 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/src/tinyfish/_utils/client/_base.py +0 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/src/tinyfish/_utils/client/async_.py +0 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/src/tinyfish/_utils/client/sync.py +0 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/src/tinyfish/_utils/exceptions.py +0 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/src/tinyfish/_utils/resource.py +0 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/src/tinyfish/_utils/sse_parser.py +0 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/src/tinyfish/agent/__init__.py +0 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/src/tinyfish/agent/types.py +0 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/src/tinyfish/browser/__init__.py +0 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/src/tinyfish/browser/types.py +0 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/src/tinyfish/fetch/__init__.py +0 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/src/tinyfish/fetch/types.py +0 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/src/tinyfish/py.typed +0 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/src/tinyfish/runs/__init__.py +0 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/src/tinyfish/runs/types.py +0 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/src/tinyfish/search/__init__.py +0 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/src/tinyfish/search/types.py +0 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/src/tinyfish/vault/__init__.py +0 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/src/tinyfish/vault/types.py +0 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/tests/__init__.py +0 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/tests/conftest.py +0 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/tests/test_agent.py +0 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/tests/test_browser.py +0 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/tests/test_client.py +0 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/tests/test_errors.py +0 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/tests/test_fetch.py +0 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/tests/test_runs.py +0 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/tests/test_search.py +0 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/tests/test_vault.py +0 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/tests/testing_guide.md +0 -0
- {tinyfish-0.5.0 → tinyfish-0.6.0}/uv.lock +0 -0
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [0.6.0](https://github.com/tinyfish-io/ux-labs/compare/sdk-py/v0.5.0...sdk-py/v0.6.0) (2026-08-11)
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
### Features
|
|
7
|
+
|
|
8
|
+
* **sdk:** wallet resource — client.wallet.get() in TypeScript and Python SDKs (PF-3454) ([#4213](https://github.com/tinyfish-io/ux-labs/issues/4213)) ([1127f1d](https://github.com/tinyfish-io/ux-labs/commit/1127f1de8acf2eef27c22eec5cd08b9cabdfaf86))
|
|
9
|
+
|
|
3
10
|
## [0.5.0](https://github.com/tinyfish-io/ux-labs/compare/sdk-py/v0.4.0...sdk-py/v0.5.0) (2026-08-04)
|
|
4
11
|
|
|
5
12
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: tinyfish
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.6.0
|
|
4
4
|
Summary: Official Python SDK for the TinyFish API
|
|
5
5
|
Requires-Python: >=3.11
|
|
6
6
|
Requires-Dist: httpx>=0.27.0
|
|
@@ -57,6 +57,7 @@ Every method below is available on both `TinyFish` (sync) and `AsyncTinyFish` (a
|
|
|
57
57
|
| [`runs.get()`](#runsget--retrieve-a-single-run) | Retrieve a single run by ID | `Run` | — |
|
|
58
58
|
| [`runs.list()`](#runslist--list-and-filter-runs) | List runs with filtering, sorting, pagination | `RunListResponse` | — |
|
|
59
59
|
| [`search.query()`](#searchquery--search-the-web) | Search the web for ranked results | `SearchQueryResponse` | Yes |
|
|
60
|
+
| `wallet.get()` | Get the caller's wallet balance, auto-reload, and rates | `WalletResponse` | — |
|
|
60
61
|
|
|
61
62
|
---
|
|
62
63
|
|
|
@@ -47,6 +47,7 @@ Every method below is available on both `TinyFish` (sync) and `AsyncTinyFish` (a
|
|
|
47
47
|
| [`runs.get()`](#runsget--retrieve-a-single-run) | Retrieve a single run by ID | `Run` | — |
|
|
48
48
|
| [`runs.list()`](#runslist--list-and-filter-runs) | List runs with filtering, sorting, pagination | `RunListResponse` | — |
|
|
49
49
|
| [`search.query()`](#searchquery--search-the-web) | Search the web for ranked results | `SearchQueryResponse` | Yes |
|
|
50
|
+
| `wallet.get()` | Get the caller's wallet balance, auto-reload, and rates | `WalletResponse` | — |
|
|
50
51
|
|
|
51
52
|
---
|
|
52
53
|
|
|
@@ -80,6 +80,16 @@ from .vault.types import (
|
|
|
80
80
|
VaultSyncItemsResponse,
|
|
81
81
|
)
|
|
82
82
|
|
|
83
|
+
# Wallet types
|
|
84
|
+
from .wallet.types import (
|
|
85
|
+
WalletAutoReload,
|
|
86
|
+
WalletAutoReloadState,
|
|
87
|
+
WalletMeter,
|
|
88
|
+
WalletPendingTopUp,
|
|
89
|
+
WalletRates,
|
|
90
|
+
WalletResponse,
|
|
91
|
+
)
|
|
92
|
+
|
|
83
93
|
__version__ = version("tinyfish")
|
|
84
94
|
|
|
85
95
|
__all__ = [
|
|
@@ -149,4 +159,11 @@ __all__ = [
|
|
|
149
159
|
"VaultDisconnectResponse",
|
|
150
160
|
"VaultListItemsResponse",
|
|
151
161
|
"VaultSyncItemsResponse",
|
|
162
|
+
# Wallet types
|
|
163
|
+
"WalletAutoReloadState",
|
|
164
|
+
"WalletAutoReload",
|
|
165
|
+
"WalletMeter",
|
|
166
|
+
"WalletRates",
|
|
167
|
+
"WalletPendingTopUp",
|
|
168
|
+
"WalletResponse",
|
|
152
169
|
]
|
|
@@ -9,6 +9,7 @@ from .fetch import AsyncFetchResource, FetchResource
|
|
|
9
9
|
from .runs import AsyncRunsResource, RunsResource
|
|
10
10
|
from .search import AsyncSearchResource, SearchResource
|
|
11
11
|
from .vault import AsyncVaultResource, VaultResource
|
|
12
|
+
from .wallet import AsyncWalletResource, WalletResource
|
|
12
13
|
|
|
13
14
|
__all__ = ["TinyFish", "AsyncTinyFish"]
|
|
14
15
|
|
|
@@ -30,6 +31,7 @@ class TinyFish(BaseSyncAPIClient):
|
|
|
30
31
|
runs: RunsResource
|
|
31
32
|
search: SearchResource
|
|
32
33
|
vault: VaultResource
|
|
34
|
+
wallet: WalletResource
|
|
33
35
|
|
|
34
36
|
def __init__(
|
|
35
37
|
self,
|
|
@@ -55,6 +57,7 @@ class TinyFish(BaseSyncAPIClient):
|
|
|
55
57
|
self.runs = RunsResource(self)
|
|
56
58
|
self.search = SearchResource(self)
|
|
57
59
|
self.vault = VaultResource(self)
|
|
60
|
+
self.wallet = WalletResource(self)
|
|
58
61
|
|
|
59
62
|
|
|
60
63
|
class AsyncTinyFish(BaseAsyncAPIClient):
|
|
@@ -69,6 +72,7 @@ class AsyncTinyFish(BaseAsyncAPIClient):
|
|
|
69
72
|
runs: AsyncRunsResource
|
|
70
73
|
search: AsyncSearchResource
|
|
71
74
|
vault: AsyncVaultResource
|
|
75
|
+
wallet: AsyncWalletResource
|
|
72
76
|
|
|
73
77
|
def __init__(
|
|
74
78
|
self,
|
|
@@ -94,3 +98,4 @@ class AsyncTinyFish(BaseAsyncAPIClient):
|
|
|
94
98
|
self.runs = AsyncRunsResource(self)
|
|
95
99
|
self.search = AsyncSearchResource(self)
|
|
96
100
|
self.vault = AsyncVaultResource(self)
|
|
101
|
+
self.wallet = AsyncWalletResource(self)
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
"""Wallet resource for retrieving wallet balance, auto-reload, and rates."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from tinyfish._utils.resource import BaseAsyncAPIResource, BaseSyncAPIResource
|
|
6
|
+
|
|
7
|
+
from .types import WalletResponse
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class WalletResource(BaseSyncAPIResource):
|
|
11
|
+
"""Retrieve the caller's wallet (sync)."""
|
|
12
|
+
|
|
13
|
+
def get(self) -> WalletResponse:
|
|
14
|
+
"""Get the caller's wallet: balance, auto-reload state, per-contract rates,
|
|
15
|
+
and any in-flight top-up.
|
|
16
|
+
|
|
17
|
+
Returns:
|
|
18
|
+
WalletResponse with the full wallet shape.
|
|
19
|
+
|
|
20
|
+
Raises:
|
|
21
|
+
AuthenticationError: Invalid API key.
|
|
22
|
+
"""
|
|
23
|
+
return self._get("/v1/wallet", cast_to=WalletResponse)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
class AsyncWalletResource(BaseAsyncAPIResource):
|
|
27
|
+
"""Retrieve the caller's wallet (async)."""
|
|
28
|
+
|
|
29
|
+
async def get(self) -> WalletResponse:
|
|
30
|
+
"""Get the caller's wallet: balance, auto-reload state, per-contract rates,
|
|
31
|
+
and any in-flight top-up.
|
|
32
|
+
|
|
33
|
+
Async version of `WalletResource.get()`.
|
|
34
|
+
|
|
35
|
+
Returns:
|
|
36
|
+
WalletResponse with the full wallet shape.
|
|
37
|
+
|
|
38
|
+
Raises:
|
|
39
|
+
AuthenticationError: Invalid API key.
|
|
40
|
+
"""
|
|
41
|
+
return await self._get("/v1/wallet", cast_to=WalletResponse)
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
"""Wallet request/response types."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from enum import StrEnum
|
|
6
|
+
from typing import Annotated, Literal
|
|
7
|
+
|
|
8
|
+
from pydantic import BaseModel, Field
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class WalletAutoReloadState(StrEnum):
|
|
12
|
+
"""Auto-reload configuration state."""
|
|
13
|
+
|
|
14
|
+
UNCONFIGURED = "unconfigured"
|
|
15
|
+
ON = "on"
|
|
16
|
+
OFF = "off"
|
|
17
|
+
PAUSED_PAYMENT_FAILED = "paused_payment_failed"
|
|
18
|
+
NEEDS_PAYMENT_METHOD = "needs_payment_method"
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
class WalletAutoReloadUnconfigured(BaseModel):
|
|
22
|
+
"""Auto-reload has never been configured for this wallet."""
|
|
23
|
+
|
|
24
|
+
state: Literal[WalletAutoReloadState.UNCONFIGURED] = Field(..., description="Current auto-reload state")
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class WalletAutoReloadConfigured(BaseModel):
|
|
28
|
+
"""Auto-reload is configured — threshold and recharge_to are always present."""
|
|
29
|
+
|
|
30
|
+
state: Literal[
|
|
31
|
+
WalletAutoReloadState.ON,
|
|
32
|
+
WalletAutoReloadState.OFF,
|
|
33
|
+
WalletAutoReloadState.PAUSED_PAYMENT_FAILED,
|
|
34
|
+
WalletAutoReloadState.NEEDS_PAYMENT_METHOD,
|
|
35
|
+
] = Field(..., description="Current auto-reload state")
|
|
36
|
+
threshold: str = Field(..., description="Balance floor that triggers a reload.")
|
|
37
|
+
recharge_to: str = Field(..., description="Balance the wallet is topped up to when a reload triggers.")
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
WalletAutoReload = Annotated[
|
|
41
|
+
WalletAutoReloadUnconfigured | WalletAutoReloadConfigured,
|
|
42
|
+
Field(discriminator="state"),
|
|
43
|
+
]
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class WalletMeter(BaseModel):
|
|
47
|
+
"""One priced product on the caller's Metronome contract."""
|
|
48
|
+
|
|
49
|
+
product_id: str = Field(..., description="Metronome product ID")
|
|
50
|
+
label: str = Field(..., description="Human-readable meter label")
|
|
51
|
+
unit_amount: str = Field(..., description="Per-unit rate, decimal string")
|
|
52
|
+
currency: str = Field(..., description="Currency code")
|
|
53
|
+
per: str | None = Field(None, description="Billable unit this meter charges per. Absent when unlabeled.")
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
class WalletRates(BaseModel):
|
|
57
|
+
"""Every priced product on the caller's Metronome contract, read live."""
|
|
58
|
+
|
|
59
|
+
meters: list[WalletMeter] = Field(..., description="Priced products on the contract")
|
|
60
|
+
as_of: str = Field(..., description="ISO timestamp the rates were read")
|
|
61
|
+
source: Literal["metronome-contract"] = Field(..., description="Rate provenance")
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
class WalletPendingTopUp(BaseModel):
|
|
65
|
+
"""An in-flight top-up. Completed, failed, and no-attempt states read null."""
|
|
66
|
+
|
|
67
|
+
amount: str = Field(..., description="Top-up amount, decimal string")
|
|
68
|
+
started_at: str = Field(..., description="ISO timestamp the top-up started")
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
class WalletResponse(BaseModel):
|
|
72
|
+
"""Wallet balance, auto-reload, per-product rates, and any in-flight top-up."""
|
|
73
|
+
|
|
74
|
+
available_balance: str = Field(
|
|
75
|
+
..., description="Current spendable balance. A negative value means the wallet is overdrawn."
|
|
76
|
+
)
|
|
77
|
+
currency: str = Field(..., description="Currency code")
|
|
78
|
+
as_of: str = Field(..., description="ISO timestamp the balance was read")
|
|
79
|
+
auto_reload: WalletAutoReload | None = Field(
|
|
80
|
+
None, description="None means the auto-reload read failed, not that it is unconfigured"
|
|
81
|
+
)
|
|
82
|
+
pending_top_up: WalletPendingTopUp | None = Field(
|
|
83
|
+
None, description="None means no in-flight top-up, or the ledger read failed"
|
|
84
|
+
)
|
|
85
|
+
rates: WalletRates | None = Field(
|
|
86
|
+
None, description="None means the rates read failed, or the wallet has no Metronome contract yet"
|
|
87
|
+
)
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
"""Tests for wallet.get — sync and async."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from typing import Any
|
|
6
|
+
|
|
7
|
+
import httpx
|
|
8
|
+
import pytest
|
|
9
|
+
from pydantic import ValidationError
|
|
10
|
+
from respx import MockRouter
|
|
11
|
+
|
|
12
|
+
from tests.conftest import BASE_URL
|
|
13
|
+
from tinyfish import AsyncTinyFish, AuthenticationError, TinyFish
|
|
14
|
+
from tinyfish.wallet.types import WalletAutoReloadState, WalletResponse
|
|
15
|
+
|
|
16
|
+
# ─── Constants ────────────────────────────────────────────────────────────────
|
|
17
|
+
|
|
18
|
+
_WALLET_PATH = "/v1/wallet"
|
|
19
|
+
_AS_OF = "2026-08-10T18:04:11.220Z"
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def _meter(**overrides: Any) -> dict[str, Any]:
|
|
23
|
+
base: dict[str, Any] = {
|
|
24
|
+
"product_id": "prod_agent",
|
|
25
|
+
"label": "Agent steps",
|
|
26
|
+
"unit_amount": "0.016000",
|
|
27
|
+
"currency": "USD",
|
|
28
|
+
"per": "step",
|
|
29
|
+
}
|
|
30
|
+
return {**base, **overrides}
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _rates(**overrides: Any) -> dict[str, Any]:
|
|
34
|
+
base: dict[str, Any] = {
|
|
35
|
+
"meters": [_meter()],
|
|
36
|
+
"as_of": _AS_OF,
|
|
37
|
+
"source": "metronome-contract",
|
|
38
|
+
}
|
|
39
|
+
return {**base, **overrides}
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def _wallet_response(**overrides: Any) -> dict[str, Any]:
|
|
43
|
+
base: dict[str, Any] = {
|
|
44
|
+
"available_balance": "21.44",
|
|
45
|
+
"currency": "USD",
|
|
46
|
+
"as_of": _AS_OF,
|
|
47
|
+
"auto_reload": {"state": "unconfigured"},
|
|
48
|
+
"pending_top_up": None,
|
|
49
|
+
"rates": _rates(),
|
|
50
|
+
}
|
|
51
|
+
return {**base, **overrides}
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
# ═══════════════════════════════════════════════════════════════════════════════
|
|
55
|
+
# wallet.get — sync
|
|
56
|
+
# ═══════════════════════════════════════════════════════════════════════════════
|
|
57
|
+
|
|
58
|
+
|
|
59
|
+
@pytest.mark.respx(base_url=BASE_URL)
|
|
60
|
+
def test_get_returns_full_shape(client: TinyFish, respx_mock: MockRouter):
|
|
61
|
+
respx_mock.get(_WALLET_PATH).mock(return_value=httpx.Response(200, json=_wallet_response()))
|
|
62
|
+
result = client.wallet.get()
|
|
63
|
+
assert isinstance(result, WalletResponse)
|
|
64
|
+
assert result.available_balance == "21.44"
|
|
65
|
+
assert result.currency == "USD"
|
|
66
|
+
assert result.as_of == _AS_OF
|
|
67
|
+
assert result.auto_reload is not None
|
|
68
|
+
assert result.auto_reload.state == WalletAutoReloadState.UNCONFIGURED
|
|
69
|
+
assert result.pending_top_up is None
|
|
70
|
+
assert result.rates is not None
|
|
71
|
+
assert len(result.rates.meters) == 1
|
|
72
|
+
assert result.rates.source == "metronome-contract"
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
@pytest.mark.respx(base_url=BASE_URL)
|
|
76
|
+
def test_get_sends_get_method(client: TinyFish, respx_mock: MockRouter):
|
|
77
|
+
route = respx_mock.get(_WALLET_PATH).mock(return_value=httpx.Response(200, json=_wallet_response()))
|
|
78
|
+
client.wallet.get()
|
|
79
|
+
assert route.calls[0].request.method == "GET"
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
@pytest.mark.respx(base_url=BASE_URL)
|
|
83
|
+
def test_get_round_trips_negative_balance(client: TinyFish, respx_mock: MockRouter):
|
|
84
|
+
respx_mock.get(_WALLET_PATH).mock(
|
|
85
|
+
return_value=httpx.Response(200, json=_wallet_response(available_balance="-14.02"))
|
|
86
|
+
)
|
|
87
|
+
result = client.wallet.get()
|
|
88
|
+
assert result.available_balance == "-14.02"
|
|
89
|
+
|
|
90
|
+
|
|
91
|
+
@pytest.mark.respx(base_url=BASE_URL)
|
|
92
|
+
def test_get_fully_degraded_response(client: TinyFish, respx_mock: MockRouter):
|
|
93
|
+
respx_mock.get(_WALLET_PATH).mock(
|
|
94
|
+
return_value=httpx.Response(200, json=_wallet_response(auto_reload=None, pending_top_up=None, rates=None))
|
|
95
|
+
)
|
|
96
|
+
result = client.wallet.get()
|
|
97
|
+
assert result.auto_reload is None
|
|
98
|
+
assert result.pending_top_up is None
|
|
99
|
+
assert result.rates is None
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
@pytest.mark.respx(base_url=BASE_URL)
|
|
103
|
+
def test_get_auto_reload_unconfigured_has_no_threshold(client: TinyFish, respx_mock: MockRouter):
|
|
104
|
+
respx_mock.get(_WALLET_PATH).mock(
|
|
105
|
+
return_value=httpx.Response(200, json=_wallet_response(auto_reload={"state": "unconfigured"}))
|
|
106
|
+
)
|
|
107
|
+
result = client.wallet.get()
|
|
108
|
+
assert result.auto_reload is not None
|
|
109
|
+
assert result.auto_reload.state == WalletAutoReloadState.UNCONFIGURED
|
|
110
|
+
assert not hasattr(result.auto_reload, "threshold")
|
|
111
|
+
assert not hasattr(result.auto_reload, "recharge_to")
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
@pytest.mark.parametrize(
|
|
115
|
+
"state",
|
|
116
|
+
["on", "off", "paused_payment_failed", "needs_payment_method"],
|
|
117
|
+
)
|
|
118
|
+
@pytest.mark.respx(base_url=BASE_URL)
|
|
119
|
+
def test_get_auto_reload_configured_states(state: str, client: TinyFish, respx_mock: MockRouter):
|
|
120
|
+
respx_mock.get(_WALLET_PATH).mock(
|
|
121
|
+
return_value=httpx.Response(
|
|
122
|
+
200,
|
|
123
|
+
json=_wallet_response(auto_reload={"state": state, "threshold": "10.00", "recharge_to": "50.00"}),
|
|
124
|
+
)
|
|
125
|
+
)
|
|
126
|
+
result = client.wallet.get()
|
|
127
|
+
assert result.auto_reload is not None
|
|
128
|
+
assert result.auto_reload.state == state
|
|
129
|
+
assert result.auto_reload.threshold == "10.00"
|
|
130
|
+
assert result.auto_reload.recharge_to == "50.00"
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
@pytest.mark.respx(base_url=BASE_URL)
|
|
134
|
+
def test_get_auto_reload_configured_missing_threshold_raises(client: TinyFish, respx_mock: MockRouter):
|
|
135
|
+
respx_mock.get(_WALLET_PATH).mock(
|
|
136
|
+
return_value=httpx.Response(200, json=_wallet_response(auto_reload={"state": "on", "recharge_to": "50.00"}))
|
|
137
|
+
)
|
|
138
|
+
with pytest.raises(ValidationError):
|
|
139
|
+
client.wallet.get()
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
@pytest.mark.respx(base_url=BASE_URL)
|
|
143
|
+
def test_get_pending_top_up(client: TinyFish, respx_mock: MockRouter):
|
|
144
|
+
respx_mock.get(_WALLET_PATH).mock(
|
|
145
|
+
return_value=httpx.Response(
|
|
146
|
+
200, json=_wallet_response(pending_top_up={"amount": "50.00", "started_at": _AS_OF})
|
|
147
|
+
)
|
|
148
|
+
)
|
|
149
|
+
result = client.wallet.get()
|
|
150
|
+
assert result.pending_top_up is not None
|
|
151
|
+
assert result.pending_top_up.amount == "50.00"
|
|
152
|
+
assert result.pending_top_up.started_at == _AS_OF
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
@pytest.mark.respx(base_url=BASE_URL)
|
|
156
|
+
def test_get_meter_without_per(client: TinyFish, respx_mock: MockRouter):
|
|
157
|
+
meter = _meter()
|
|
158
|
+
del meter["per"]
|
|
159
|
+
respx_mock.get(_WALLET_PATH).mock(
|
|
160
|
+
return_value=httpx.Response(200, json=_wallet_response(rates=_rates(meters=[meter])))
|
|
161
|
+
)
|
|
162
|
+
result = client.wallet.get()
|
|
163
|
+
assert result.rates is not None
|
|
164
|
+
assert result.rates.meters[0].per is None
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
@pytest.mark.respx(base_url=BASE_URL)
|
|
168
|
+
def test_get_strips_unknown_field(client: TinyFish, respx_mock: MockRouter):
|
|
169
|
+
respx_mock.get(_WALLET_PATH).mock(
|
|
170
|
+
return_value=httpx.Response(200, json=_wallet_response(unexpected_field="surprise"))
|
|
171
|
+
)
|
|
172
|
+
result = client.wallet.get()
|
|
173
|
+
assert result.available_balance == "21.44"
|
|
174
|
+
assert not hasattr(result, "unexpected_field")
|
|
175
|
+
|
|
176
|
+
|
|
177
|
+
@pytest.mark.respx(base_url=BASE_URL)
|
|
178
|
+
def test_get_401(client: TinyFish, respx_mock: MockRouter):
|
|
179
|
+
respx_mock.get(_WALLET_PATH).mock(return_value=httpx.Response(401, json={"error": {"message": "unauthorized"}}))
|
|
180
|
+
with pytest.raises(AuthenticationError):
|
|
181
|
+
client.wallet.get()
|
|
182
|
+
|
|
183
|
+
|
|
184
|
+
# ═══════════════════════════════════════════════════════════════════════════════
|
|
185
|
+
# wallet.get — async
|
|
186
|
+
# ═══════════════════════════════════════════════════════════════════════════════
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
@pytest.mark.respx(base_url=BASE_URL)
|
|
190
|
+
async def test_async_get_returns_full_shape(async_client: AsyncTinyFish, respx_mock: MockRouter):
|
|
191
|
+
respx_mock.get(_WALLET_PATH).mock(return_value=httpx.Response(200, json=_wallet_response()))
|
|
192
|
+
async with async_client as c:
|
|
193
|
+
result = await c.wallet.get()
|
|
194
|
+
assert isinstance(result, WalletResponse)
|
|
195
|
+
assert result.available_balance == "21.44"
|
|
196
|
+
assert result.rates is not None
|
|
197
|
+
assert len(result.rates.meters) == 1
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
@pytest.mark.respx(base_url=BASE_URL)
|
|
201
|
+
async def test_async_get_round_trips_negative_balance(async_client: AsyncTinyFish, respx_mock: MockRouter):
|
|
202
|
+
respx_mock.get(_WALLET_PATH).mock(
|
|
203
|
+
return_value=httpx.Response(200, json=_wallet_response(available_balance="-14.02"))
|
|
204
|
+
)
|
|
205
|
+
async with async_client as c:
|
|
206
|
+
result = await c.wallet.get()
|
|
207
|
+
assert result.available_balance == "-14.02"
|
|
208
|
+
|
|
209
|
+
|
|
210
|
+
@pytest.mark.respx(base_url=BASE_URL)
|
|
211
|
+
async def test_async_get_fully_degraded_response(async_client: AsyncTinyFish, respx_mock: MockRouter):
|
|
212
|
+
respx_mock.get(_WALLET_PATH).mock(
|
|
213
|
+
return_value=httpx.Response(200, json=_wallet_response(auto_reload=None, pending_top_up=None, rates=None))
|
|
214
|
+
)
|
|
215
|
+
async with async_client as c:
|
|
216
|
+
result = await c.wallet.get()
|
|
217
|
+
assert result.auto_reload is None
|
|
218
|
+
assert result.pending_top_up is None
|
|
219
|
+
assert result.rates is None
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
@pytest.mark.respx(base_url=BASE_URL)
|
|
223
|
+
async def test_async_get_auto_reload_configured_missing_threshold_raises(
|
|
224
|
+
async_client: AsyncTinyFish, respx_mock: MockRouter
|
|
225
|
+
):
|
|
226
|
+
respx_mock.get(_WALLET_PATH).mock(
|
|
227
|
+
return_value=httpx.Response(200, json=_wallet_response(auto_reload={"state": "on", "recharge_to": "50.00"}))
|
|
228
|
+
)
|
|
229
|
+
async with async_client as c:
|
|
230
|
+
with pytest.raises(ValidationError):
|
|
231
|
+
await c.wallet.get()
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
@pytest.mark.respx(base_url=BASE_URL)
|
|
235
|
+
async def test_async_get_401(async_client: AsyncTinyFish, respx_mock: MockRouter):
|
|
236
|
+
respx_mock.get(_WALLET_PATH).mock(return_value=httpx.Response(401, json={"error": {"message": "unauthorized"}}))
|
|
237
|
+
async with async_client as c:
|
|
238
|
+
with pytest.raises(AuthenticationError):
|
|
239
|
+
await c.wallet.get()
|
|
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
|
|
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
|
|
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
|
|
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
|
|
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
|