From 62121b7965bdaf78b314981b000dd7097f9ed849 Mon Sep 17 00:00:00 2001 From: Alex Barnsley <8069294+alexbarnsley@users.noreply.github.com> Date: Wed, 26 Mar 2025 17:29:49 +0000 Subject: [PATCH 1/4] add threshold to workflow --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 97eca57..9908546 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -31,4 +31,4 @@ jobs: run: | . venv/bin/activate mkdir -p test-reports - pytest -v -s --junitxml=test-reports/junit.xml --cov=client --cov-config=.coveragerc --cov-report xml + pytest -v -s --junitxml=test-reports/junit.xml --cov=client --cov-config=.coveragerc --cov-report xml --cov-fail-under=100 From 37d4921b0678eacf6621632a210926aefb86fe5a Mon Sep 17 00:00:00 2001 From: Alex Barnsley <8069294+alexbarnsley@users.noreply.github.com> Date: Wed, 26 Mar 2025 17:33:18 +0000 Subject: [PATCH 2/4] transactions coverage --- tests/api/test_transactions.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/tests/api/test_transactions.py b/tests/api/test_transactions.py index dde6db9..3b511e4 100644 --- a/tests/api/test_transactions.py +++ b/tests/api/test_transactions.py @@ -135,6 +135,22 @@ def test_all_unconfirmed_calls_correct_url_with_additional_params(): 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/api/transactions/unconfirmed/{}'.format(transaction_id), + json={'success': True}, + status=200 + ) + + client = ArkClient('http://127.0.0.1:4002/api') + client.transactions.get_unconfirmed(transaction_id) + assert len(responses.calls) == 1 + assert responses.calls[0].request.url == 'http://127.0.0.1:4002/api/transactions/unconfirmed/12345' + def test_schemas_calls_correct_url(): responses.add( responses.GET, From d3b4411fe9c8fbbe72b41cdc25a97f256435fbef Mon Sep 17 00:00:00 2001 From: Alex Barnsley <8069294+alexbarnsley@users.noreply.github.com> Date: Wed, 26 Mar 2025 18:06:04 +0000 Subject: [PATCH 3/4] update connection session handling of hostname --- client/connection.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/client/connection.py b/client/connection.py index 0df0f20..1fd1f35 100644 --- a/client/connection.py +++ b/client/connection.py @@ -25,8 +25,11 @@ class ClientHosts(TypedDict): class Session(requests.Session): def __init__(self, *args, **kwargs): - if 'hostname' in kwargs: - self.hostname = kwargs.pop('hostname') + if 'hostname' not in kwargs: + raise ValueError('hostname is required') + + self.hostname = kwargs.pop('hostname') + super().__init__(*args, **kwargs) @retry @@ -37,8 +40,8 @@ def send(self, request, **kwargs): return super().send(request, **kwargs) def prepare_request(self, request): - if self.hostname is not None: - request.url = f'{self.hostname}/{request.url}' + request.url = f'{self.hostname}/{request.url}' + return super().prepare_request(request) class Connection(object): From e97135606ffad730b955ff8544e7bc4bc19d14ec Mon Sep 17 00:00:00 2001 From: Alex Barnsley <8069294+alexbarnsley@users.noreply.github.com> Date: Wed, 26 Mar 2025 18:06:09 +0000 Subject: [PATCH 4/4] test --- tests/test_connection.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/tests/test_connection.py b/tests/test_connection.py index dab0964..26dbf07 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -4,7 +4,7 @@ import responses -from client.connection import Connection +from client.connection import Connection, Session from client.exceptions import ArkHTTPException @@ -162,3 +162,31 @@ def test_http_methods_call_correct_url_with_params_and_return_correct_response(m assert data == {'success': True} assert len(responses.calls) == 1 assert responses.calls[0].request.url == 'http://127.0.0.1:4003/spongebob?foo=bar' + + +def test_session_detects_hostname_correctly(): + session = Session(hostname="test.com") + assert session.hostname == "test.com" + assert isinstance(session, requests.Session) + + +def test_session_throws_error_when_missing_hostname(): + with pytest.raises(ValueError) as exception: + Session() + + assert exception.value == 'hostname is required' + + +def test_session_prepends_hostname_to_url(): + responses.add( + responses.GET, + 'http://test.com/spongebob', + json={'success': True}, + status=200 + ) + + session = Session(hostname="http://test.com") + + session.get('spongebob') + assert len(responses.calls) == 1 + assert responses.calls[0].request.url == 'http://test.com/spongebob'