Skip to content

Commit ef7b92f

Browse files
committed
fix: remove aleph credit list
1 parent 9475165 commit ef7b92f

File tree

2 files changed

+1
-153
lines changed

2 files changed

+1
-153
lines changed

src/aleph_client/commands/credit.py

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,13 @@
33
from typing import Annotated, Optional
44

55
import typer
6-
from aiohttp import ClientResponseError
76
from aleph.sdk import AlephHttpClient
87
from aleph.sdk.account import _load_account
98
from aleph.sdk.conf import settings
10-
from aleph.sdk.query.filters import CreditsFilter
119
from aleph.sdk.types import AccountFromPrivateKey
1210
from aleph.sdk.utils import displayable_amount
1311
from rich.console import Console
1412
from rich.panel import Panel
15-
from rich.table import Table
1613
from rich.text import Text
1714

1815
from aleph_client.commands import help_strings
@@ -68,40 +65,3 @@ async def show(
6865
)
6966
else:
7067
typer.echo("Error: Please provide either a private key, private key file, or an address.")
71-
72-
73-
@app.command(name="list")
74-
async def list_credits(
75-
page_size: Annotated[int, typer.Option(help="Numbers of element per page")] = 100,
76-
page: Annotated[int, typer.Option(help="Current Page")] = 1,
77-
min_balance: Annotated[
78-
Optional[int], typer.Option(help="Minimum balance required to be taken into account")
79-
] = None,
80-
json: Annotated[bool, typer.Option(help="Display as json")] = False,
81-
):
82-
try:
83-
async with AlephHttpClient(api_server=settings.API_HOST) as client:
84-
credit_filter = CreditsFilter(min_balance=min_balance) if min_balance else None
85-
filtered_credits = await client.get_credits(credit_filter=credit_filter, page_size=page_size, page=page)
86-
if json:
87-
typer.echo(filtered_credits.model_dump_json(indent=4))
88-
else:
89-
table = Table(title="Credits Information", border_style="white")
90-
table.add_column("Address", style="bright_cyan")
91-
table.add_column("Credits", justify="right", style="bright_cyan")
92-
93-
for credit in filtered_credits.credit_balances:
94-
table.add_row(credit.address, f"{displayable_amount(credit.credits, decimals=2)}")
95-
96-
# Add pagination footer
97-
pagination_info = Text.assemble(
98-
f"Page: {filtered_credits.pagination_page} of {filtered_credits.pagination_total} | ",
99-
f"Items per page: {filtered_credits.pagination_per_page} | ",
100-
f"Page size: {filtered_credits.pagination_total}",
101-
)
102-
table.caption = pagination_info
103-
104-
console.print(table)
105-
except ClientResponseError as e:
106-
typer.echo("Failed to retrieve credits.")
107-
raise (e)

tests/unit/test_credits.py

Lines changed: 1 addition & 113 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import pytest
66
from aiohttp import ClientResponseError
77

8-
from aleph_client.commands.credit import list_credits, show
8+
from aleph_client.commands.credit import show
99

1010

1111
@pytest.fixture
@@ -181,115 +181,3 @@ async def run(mock_get):
181181
)
182182

183183
await run()
184-
185-
186-
@pytest.mark.asyncio
187-
async def test_list_credits_default(mock_credits_list_response, capsys):
188-
"""Test the list_credits command with default parameters."""
189-
190-
@patch("aiohttp.ClientSession.get")
191-
async def run(mock_get):
192-
mock_get.return_value = mock_credits_list_response
193-
194-
# Run the list_credits command with default parameters
195-
await list_credits(
196-
page_size=100,
197-
page=1,
198-
min_balance=None,
199-
json=False,
200-
)
201-
202-
await run()
203-
captured = capsys.readouterr()
204-
assert "Credits Information" in captured.out
205-
assert "0x1234567890123456789012345678901234567890" in captured.out
206-
# The credits might be displayed in their raw form without formatting
207-
assert "1000000000" in captured.out
208-
209-
210-
@pytest.mark.asyncio
211-
async def test_list_credits_with_filter(mock_credits_list_response, capsys):
212-
"""Test the list_credits command with min_balance filter."""
213-
214-
@patch("aiohttp.ClientSession.get")
215-
async def run(mock_get):
216-
mock_get.return_value = mock_credits_list_response
217-
218-
# Run the list_credits command with min_balance filter
219-
await list_credits(
220-
page_size=100,
221-
page=1,
222-
min_balance=1000000, # 0.01 credits with 8 decimals
223-
json=False,
224-
)
225-
226-
await run()
227-
captured = capsys.readouterr()
228-
assert "Credits Information" in captured.out
229-
230-
231-
@pytest.mark.asyncio
232-
async def test_list_credits_json_output(mock_credits_list_response, capsys):
233-
"""Test the list_credits command with JSON output."""
234-
235-
@patch("aiohttp.ClientSession.get")
236-
async def run(mock_get):
237-
mock_get.return_value = mock_credits_list_response
238-
239-
# Run the list_credits command with JSON output
240-
await list_credits(
241-
page_size=100,
242-
page=1,
243-
min_balance=None,
244-
json=True,
245-
)
246-
247-
await run()
248-
captured = capsys.readouterr()
249-
assert "credit_balances" in captured.out
250-
assert "pagination_page" in captured.out
251-
252-
253-
@pytest.mark.asyncio
254-
async def test_list_credits_custom_pagination(mock_credits_list_response):
255-
"""Test the list_credits command with custom pagination parameters."""
256-
257-
@patch("aiohttp.ClientSession.get")
258-
async def run(mock_get):
259-
mock_get.return_value = mock_credits_list_response
260-
261-
# Run the list_credits command with custom pagination
262-
await list_credits(
263-
page_size=50,
264-
page=2,
265-
min_balance=None,
266-
json=False,
267-
)
268-
269-
# Verify that the parameters were passed correctly
270-
# In the SDK, these parameters are passed as part of the 'params' argument, not in the URL
271-
called_params = mock_get.call_args[1]["params"]
272-
assert called_params["pagination"] == "50"
273-
assert called_params["page"] == "2"
274-
275-
await run()
276-
277-
278-
@pytest.mark.asyncio
279-
async def test_list_credits_api_error(mock_credit_error_response):
280-
"""Test the list_credits command handling API errors."""
281-
282-
@patch("aiohttp.ClientSession.get")
283-
async def run(mock_get):
284-
mock_get.return_value = mock_credit_error_response
285-
286-
# Run the list_credits command and expect it to handle the error
287-
with pytest.raises(ClientResponseError):
288-
await list_credits(
289-
page_size=100,
290-
page=1,
291-
min_balance=None,
292-
json=False,
293-
)
294-
295-
await run()

0 commit comments

Comments
 (0)