Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions client/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,7 @@ def giveup_handler(_):
class Session(requests.Session):

def __init__(self, *args, **kwargs):
if 'hostname' in kwargs:
self.hostname = kwargs.pop('hostname')
self.hostname = kwargs.pop('hostname', None)
super().__init__(*args, **kwargs)

@retry
Expand Down
72 changes: 72 additions & 0 deletions tests/api/test_delegates.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,75 @@ def test_get_calls_correct_url():

assert len(responses.calls) == 1
assert responses.calls[0].request.url == 'http://127.0.0.1:4002/delegates/12345'


def test_blocks_calls_correct_url_with_default_params():
delegate_id = '12345'
responses.add(
responses.GET,
'http://127.0.0.1:4002/delegates/{}/blocks'.format(delegate_id),
json={'success': True},
status=200
)

client = ArkClient('http://127.0.0.1:4002')
client.delegates.blocks(delegate_id)
assert len(responses.calls) == 1
assert responses.calls[0].request.url == (
'http://127.0.0.1:4002/delegates/12345/blocks?limit=100'
)


def test_blocks_calls_correct_url_with_passed_in_params():
delegate_id = '12345'
responses.add(
responses.GET,
'http://127.0.0.1:4002/delegates/{}/blocks'.format(delegate_id),
json={'success': True},
status=200
)

client = ArkClient('http://127.0.0.1:4002')
client.delegates.blocks(delegate_id, page=5, limit=69)
assert len(responses.calls) == 1
assert responses.calls[0].request.url.startswith(
'http://127.0.0.1:4002/delegates/12345/blocks?'
)
assert 'page=5' in responses.calls[0].request.url
assert 'limit=69' in responses.calls[0].request.url


def test_voters_calls_correct_url_with_default_params():
delegate_id = '12345'
responses.add(
responses.GET,
'http://127.0.0.1:4002/delegates/{}/voters'.format(delegate_id),
json={'success': True},
status=200
)

client = ArkClient('http://127.0.0.1:4002')
client.delegates.voters(delegate_id)
assert len(responses.calls) == 1
assert responses.calls[0].request.url == (
'http://127.0.0.1:4002/delegates/12345/voters?limit=100'
)


def test_voters_calls_correct_url_with_passed_in_params():
delegate_id = '12345'
responses.add(
responses.GET,
'http://127.0.0.1:4002/delegates/{}/voters'.format(delegate_id),
json={'success': True},
status=200
)

client = ArkClient('http://127.0.0.1:4002')
client.delegates.voters(delegate_id, page=5, limit=69)
assert len(responses.calls) == 1
assert responses.calls[0].request.url.startswith(
'http://127.0.0.1:4002/delegates/12345/voters?'
)
assert 'page=5' in responses.calls[0].request.url
assert 'limit=69' in responses.calls[0].request.url
36 changes: 36 additions & 0 deletions tests/api/test_locks.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,39 @@ def test_get_calls_correct_url():

assert len(responses.calls) == 1
assert responses.calls[0].request.url == 'http://127.0.0.1:4002/locks/12345'


def test_unlocked_calls_correct_url_with_default_params():
responses.add(
responses.POST,
'http://127.0.0.1:4002/locks/unlocked',
json={'success': True},
status=200
)

client = ArkClient('http://127.0.0.1:4002')
client.locks.unlocked({'ids': ['12345', '67890']})
assert len(responses.calls) == 1
assert responses.calls[0].request.url == 'http://127.0.0.1:4002/locks/unlocked?limit=100'
assert json.loads(responses.calls[0].request.body.decode()) == {
'ids': ['12345', '67890']
}


def test_unlocked_calls_correct_url_with_passed_in_params():
responses.add(
responses.POST,
'http://127.0.0.1:4002/locks/unlocked',
json={'success': True},
status=200
)

client = ArkClient('http://127.0.0.1:4002')
client.locks.unlocked({'ids': ['12345']}, page=5, limit=69)
assert len(responses.calls) == 1
assert responses.calls[0].request.url.startswith('http://127.0.0.1:4002/locks/unlocked?')
assert 'page=5' in responses.calls[0].request.url
assert 'limit=69' in responses.calls[0].request.url
assert json.loads(responses.calls[0].request.body.decode()) == {
'ids': ['12345']
}
48 changes: 48 additions & 0 deletions tests/api/test_transactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,3 +134,51 @@ def test_all_unconfirmed_calls_correct_url_with_additional_params():
assert 'page=5' in responses.calls[0].request.url
assert 'limit=69' in responses.calls[0].request.url
assert 'orderBy=timestamp.epoch' in responses.calls[0].request.url


def test_get_unconfirmed_calls_correct_url():
transaction_id = '12345'
responses.add(
responses.GET,
'http://127.0.0.1:4002/transactions/unconfirmed/{}'.format(transaction_id),
json={'success': True},
status=200
)

client = ArkClient('http://127.0.0.1:4002')
client.transactions.get_unconfirmed(transaction_id)

assert len(responses.calls) == 1
assert responses.calls[0].request.url == (
'http://127.0.0.1:4002/transactions/unconfirmed/12345'
)


def test_types_calls_correct_url():
responses.add(
responses.GET,
'http://127.0.0.1:4002/transactions/types',
json={'success': True},
status=200
)

client = ArkClient('http://127.0.0.1:4002')
client.transactions.types()

assert len(responses.calls) == 1
assert responses.calls[0].request.url == 'http://127.0.0.1:4002/transactions/types'


def test_fees_calls_correct_url():
responses.add(
responses.GET,
'http://127.0.0.1:4002/transactions/fees',
json={'success': True},
status=200
)

client = ArkClient('http://127.0.0.1:4002')
client.transactions.fees()

assert len(responses.calls) == 1
assert responses.calls[0].request.url == 'http://127.0.0.1:4002/transactions/fees'
17 changes: 16 additions & 1 deletion tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

import responses

from client.connection import Connection
from client.connection import Connection, Session
from client.exceptions import ArkHTTPException


Expand All @@ -14,6 +14,21 @@ def test_connection_creation_sets_default_session_headers_and_variables():
assert isinstance(connection.session, requests.Session)
assert connection.session.headers['Content-Type'] == 'application/json'


def test_session_prepare_request_prefixes_url_with_hostname():
session = Session(hostname='http://127.0.0.1:4003')
prepared = session.prepare_request(requests.Request('GET', 'spongebob'))
assert prepared.url == 'http://127.0.0.1:4003/spongebob'


def test_session_prepare_request_leaves_url_unchanged_without_hostname():
session = Session()
assert session.hostname is None

prepared = session.prepare_request(requests.Request('GET', 'http://127.0.0.1:4003/spongebob'))
assert prepared.url == 'http://127.0.0.1:4003/spongebob'


def test_connection_request_retry_successful():
responses.add(
responses.GET,
Expand Down