mirror of
https://github.com/Hestia-Homes/Model.git
synced 2026-06-08 11:17:27 +00:00
Fetch all pages in get_plans pagination loop 🟥
This commit is contained in:
parent
f83ddd05a8
commit
6dfca082f8
1 changed files with 28 additions and 0 deletions
|
|
@ -119,6 +119,34 @@ def test_get_plans_propagates_http_error(
|
|||
client.get_plans()
|
||||
|
||||
|
||||
def test_get_plans_multi_page_fetches_all_pages(
|
||||
client: MagicPlanClient, mock_session: MagicMock
|
||||
) -> None:
|
||||
# Arrange
|
||||
page1_plan = _load_fixture("magicplan_api_plans_response_example.json")["data"][
|
||||
"plans"
|
||||
][0]
|
||||
page2_plan = {**page1_plan, "id": "page-2-plan-id"}
|
||||
page1_response = MagicMock()
|
||||
page1_response.json.return_value = {
|
||||
"data": {"paging": {"page": 1, "next_page": True, "count": 2}, "plans": [page1_plan]}
|
||||
}
|
||||
page2_response = MagicMock()
|
||||
page2_response.json.return_value = {
|
||||
"data": {"paging": {"page": 2, "next_page": False, "count": 2}, "plans": [page2_plan]}
|
||||
}
|
||||
mock_session.get.side_effect = [page1_response, page2_response]
|
||||
# Act
|
||||
result = client.get_plans()
|
||||
# Assert
|
||||
assert mock_session.get.call_count == 2
|
||||
mock_session.get.assert_any_call(f"{BASE_URL}/workgroups/plans", params={"page": 1})
|
||||
mock_session.get.assert_any_call(f"{BASE_URL}/workgroups/plans", params={"page": 2})
|
||||
assert len(result) == 2
|
||||
assert result[0].id == page1_plan["id"]
|
||||
assert result[1].id == "page-2-plan-id"
|
||||
|
||||
|
||||
# --- get_plan ---
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue