|
| 1 | +import responses |
| 2 | +from client import ArkClient |
| 3 | + |
| 4 | + |
| 5 | +def test_all_calls_correct_url(): |
| 6 | + responses.add( |
| 7 | + responses.GET, |
| 8 | + 'http://127.0.0.1:4002/api/receipts', |
| 9 | + json={'success': True}, |
| 10 | + status=200 |
| 11 | + ) |
| 12 | + |
| 13 | + client = ArkClient('http://127.0.0.1:4002/api') |
| 14 | + client.receipts.all() |
| 15 | + assert len(responses.calls) == 1 |
| 16 | + assert responses.calls[0].request.url == 'http://127.0.0.1:4002/api/receipts' |
| 17 | + |
| 18 | + |
| 19 | +def test_all_calls_correct_url_with_params(): |
| 20 | + responses.add( |
| 21 | + responses.GET, |
| 22 | + 'http://127.0.0.1:4002/api/receipts', |
| 23 | + json={'success': True}, |
| 24 | + status=200 |
| 25 | + ) |
| 26 | + |
| 27 | + client = ArkClient('http://127.0.0.1:4002/api') |
| 28 | + client.receipts.all(query_param1='value1', query_param2='value2') |
| 29 | + assert len(responses.calls) == 1 |
| 30 | + assert responses.calls[0].request.url.startswith('http://127.0.0.1:4002/api/receipts?') |
| 31 | + assert 'query_param1=value1' in responses.calls[0].request.url |
| 32 | + assert 'query_param2=value2' in responses.calls[0].request.url |
| 33 | + |
| 34 | + |
| 35 | +def test_get_calls_correct_url(): |
| 36 | + transaction_hash = '12345' |
| 37 | + responses.add( |
| 38 | + responses.GET, |
| 39 | + f'http://127.0.0.1:4002/api/receipts?txHash={transaction_hash}', |
| 40 | + json={'success': True}, |
| 41 | + status=200 |
| 42 | + ) |
| 43 | + |
| 44 | + client = ArkClient('http://127.0.0.1:4002/api') |
| 45 | + client.receipts.get(transaction_hash) |
| 46 | + assert len(responses.calls) == 1 |
| 47 | + assert responses.calls[0].request.url.startswith('http://127.0.0.1:4002/api/receipts?') |
| 48 | + assert f'txHash={transaction_hash}' in responses.calls[0].request.url |
0 commit comments