Skip to content

Commit

Permalink
refactor(api): update expiry returns GroupFundingSourceResponse
Browse files Browse the repository at this point in the history
  • Loading branch information
thekaveman committed Mar 19, 2024
1 parent 9932a59 commit e866872
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
4 changes: 2 additions & 2 deletions littlepay/api/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,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
) -> dict:
) -> GroupFundingSourceResponse:
"""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)}

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

return response.list[0]
return GroupFundingSourceResponse(**response.list[0])
34 changes: 30 additions & 4 deletions tests/api/test_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,28 @@
from littlepay.api.groups import GroupFundingSourceResponse, GroupResponse, GroupsMixin


@pytest.fixture
def ListResponse_GroupFundingSources():
items = [
dict(
id="0",
participant_id="zero_0",
concession_expiry="2024-03-19T20:00:00Z",
concession_created_at="2024-03-19T20:00:00Z",
concession_updated_at="2024-03-19T20:00:00Z",
),
dict(
id="1",
participant_id="one_1",
concession_expiry="2024-03-19T20:00:00Z",
concession_created_at="2024-03-19T20:00:00Z",
concession_updated_at="2024-03-19T20:00:00Z",
),
dict(id="2", participant_id="two_2", concession_expiry="", concession_created_at=""),
]
return ListResponse(list=items, total_count=3)


@pytest.fixture
def mock_ClientProtocol_get_list_Groups(mocker):
items = [
Expand All @@ -30,8 +52,10 @@ def mock_ClientProtocol_post_link_concession_group_funding_source(mocker):


@pytest.fixture
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 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 test_GroupResponse_csv():
Expand Down Expand Up @@ -213,7 +237,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_sample, mocker
mock_ClientProtocol_put_update_concession_group_funding_source, ListResponse_GroupFundingSources, mocker
):
client = GroupsMixin()
mocker.patch.object(client, "_format_concession_expiry", return_value="formatted concession expiry")
Expand All @@ -224,4 +248,6 @@ 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 == ListResponse_sample.list[0]

expected = GroupFundingSourceResponse(**ListResponse_GroupFundingSources.list[0])
assert result == expected

0 comments on commit e866872

Please sign in to comment.