diff --git a/littlepay/api/groups.py b/littlepay/api/groups.py index 4eef920..329f50f 100644 --- a/littlepay/api/groups.py +++ b/littlepay/api/groups.py @@ -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]) diff --git a/tests/api/test_groups.py b/tests/api/test_groups.py index cf24156..abbb7fc 100644 --- a/tests/api/test_groups.py +++ b/tests/api/test_groups.py @@ -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 = [ @@ -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(): @@ -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") @@ -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