Skip to content

Commit

Permalink
Fix: update group funding source expiry (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
angela-tran authored Jun 13, 2024
2 parents 0adb981 + 2ef200a commit 4126d9a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 15 deletions.
10 changes: 3 additions & 7 deletions littlepay/api/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from datetime import datetime, timezone
from typing import Generator

from littlepay.api import ClientProtocol, ListResponse
from littlepay.api import ClientProtocol
from littlepay.api.funding_sources import FundingSourceDateFields, FundingSourcesMixin


Expand Down Expand Up @@ -100,13 +100,9 @@ def link_concession_group_funding_source(self, group_id: str, funding_source_id:

return self._post(endpoint, data, dict)

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

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

return GroupFundingSourceResponse(**response.list[0])
return self._put(endpoint, data, dict)
14 changes: 6 additions & 8 deletions tests/api/test_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,9 @@ def mock_ClientProtocol_post_link_concession_group_funding_source(mocker):


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


def test_GroupResponse_csv():
Expand Down Expand Up @@ -302,7 +301,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, ListResponse_GroupFundingSources, mocker
mock_ClientProtocol_put_update_concession_group_funding_source, mocker
):
client = GroupsMixin()
mocker.patch.object(client, "_format_expiry", return_value="formatted expiry")
Expand All @@ -311,8 +310,7 @@ def test_GroupsMixin_update_concession_group_funding_source_expiry(

endpoint = client.concession_group_funding_source_endpoint("group-1234", "funding-source-1234")
mock_ClientProtocol_put_update_concession_group_funding_source.assert_called_once_with(
endpoint, {"expiry": "formatted expiry"}, ListResponse
endpoint, {"expiry": "formatted expiry"}, dict
)

expected = GroupFundingSourceResponse(**ListResponse_GroupFundingSources.list[0])
assert result == expected
assert result == {"status_code": 204}

0 comments on commit 4126d9a

Please sign in to comment.