Skip to content

Commit

Permalink
refactor(api): pull out the (only) list item when updating expiry
Browse files Browse the repository at this point in the history
PUT returns a ListResponse, but with only a single item, so pull it out
and return that instead to simplify caller consumption
  • Loading branch information
thekaveman committed Mar 19, 2024
1 parent f4ca317 commit 5655864
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 12 deletions.
6 changes: 4 additions & 2 deletions littlepay/api/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,11 @@ def link_concession_group_funding_source(

def update_concession_group_funding_source_expiry(
self, group_id: str, funding_source_id: str, concession_expiry: datetime
) -> ListResponse:
) -> dict:
"""Update the expiry of a funding source already linked to a concession group."""
endpoint = self.concession_group_funding_source_endpoint(group_id)
data = {"id": funding_source_id, "concession_expiry": self._format_concession_expiry(concession_expiry)}

return self._put(endpoint, data, ListResponse)
response = self._put(endpoint, data, ListResponse)

return response.list[0]
5 changes: 0 additions & 5 deletions tests/api/test_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ def SampleResponse_json():
return {"one": "single", "two": "double", "three": 3}


@pytest.fixture
def ListResponse_sample():
return ListResponse(list=[{"one": 1}, {"two": 2}, {"three": 3}], total_count=3)


@pytest.fixture
def default_list_params():
return dict(page=1, perPage=100)
Expand Down
9 changes: 4 additions & 5 deletions tests/api/test_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,8 @@ def mock_ClientProtocol_post_link_concession_group_funding_source(mocker):


@pytest.fixture
def mock_ClientProtocol_put_update_concession_group_funding_source(mocker):
response = {"status_code": 200}
return mocker.patch("littlepay.api.ClientProtocol._put", side_effect=lambda *args, **kwargs: response)
def mock_ClientProtocol_put_update_concession_group_funding_source(mocker, ListResponse_sample):
return mocker.patch("littlepay.api.ClientProtocol._put", side_effect=lambda *args, **kwargs: ListResponse_sample)


def test_GroupResponse_csv():
Expand Down Expand Up @@ -181,7 +180,7 @@ def test_GroupsMixin_link_concession_group_funding_source_expiry(


def test_GroupsMixin_update_concession_group_funding_source_expiry(
mock_ClientProtocol_put_update_concession_group_funding_source, mocker
mock_ClientProtocol_put_update_concession_group_funding_source, ListResponse_sample, mocker
):
client = GroupsMixin()
mocker.patch.object(client, "_format_concession_expiry", return_value="formatted concession expiry")
Expand All @@ -192,4 +191,4 @@ def test_GroupsMixin_update_concession_group_funding_source_expiry(
mock_ClientProtocol_put_update_concession_group_funding_source.assert_called_once_with(
endpoint, {"id": "funding-source-1234", "concession_expiry": "formatted concession expiry"}, ListResponse
)
assert result == {"status_code": 200}
assert result == ListResponse_sample.list[0]
6 changes: 6 additions & 0 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from pytest_socket import disable_socket

from littlepay import __version__
from littlepay.api import ListResponse
import littlepay.config
from littlepay.commands import RESULT_SUCCESS

Expand Down Expand Up @@ -140,3 +141,8 @@ def mock_ClientProtocol_make_endpoint(mocker, url):
mocker.patch(
"littlepay.api.ClientProtocol._make_endpoint", side_effect=lambda *args: f"{url}/{'/'.join([a for a in args if a])}"
)


@pytest.fixture
def ListResponse_sample():
return ListResponse(list=[{"one": 1}, {"two": 2}, {"three": 3}], total_count=3)

0 comments on commit 5655864

Please sign in to comment.