|
5 | 5 | import pytest |
6 | 6 | from aiohttp import ClientResponseError |
7 | 7 |
|
8 | | -from aleph_client.commands.credit import list_credits, show |
| 8 | +from aleph_client.commands.credit import show |
9 | 9 |
|
10 | 10 |
|
11 | 11 | @pytest.fixture |
@@ -181,115 +181,3 @@ async def run(mock_get): |
181 | 181 | ) |
182 | 182 |
|
183 | 183 | 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