Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: update group funding source expiry #64

Merged
merged 2 commits into from
Jun 13, 2024
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
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}
Loading