Skip to content

Commit 5165ecd

Browse files
committed
test pagination and iteration
1 parent 0820ca1 commit 5165ecd

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

src/msgraph_core/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,6 @@
1414
from .base_graph_request_adapter import BaseGraphRequestAdapter
1515
from .graph_client_factory import GraphClientFactory
1616
from .tasks import PageIterator
17+
from .models import PageResult
1718

1819
__version__ = SDK_VERSION

src/msgraph_core/tasks/page_iterator.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
and models modules.
1818
"""
1919

20-
from typing import Callable, Optional, Union, Dict, Any
20+
from typing import Callable, Optional, Union, Dict, List
2121

2222
from typing import TypeVar
2323
from requests.exceptions import InvalidURL
@@ -28,7 +28,7 @@
2828
from kiota_abstractions.request_information import RequestInformation
2929
from kiota_abstractions.serialization.parsable import Parsable
3030

31-
from msgraph_core.models import PageResult # pylint: disable=no-name-in-module, import-error
31+
from msgraph_core.models.page_result import PageResult # pylint: disable=no-name-in-module, import-error
3232

3333
T = TypeVar('T', bound=Parsable)
3434

@@ -75,9 +75,9 @@ def __init__(
7575
self.object_type = self.current_page.value[
7676
0].__class__.__name__ if self.current_page.value else None
7777
page = self.current_page
78-
self._next_link = response.get('@odata.nextLink', '') if isinstance(
78+
self._next_link = response.get('odata_next_link', '') if isinstance(
7979
response, dict
80-
) else getattr(response, '@odata.nextLink', '')
80+
) else getattr(response, 'odata_next_link', '')
8181
self._delta_link = response.get('@odata.deltaLink', '') if isinstance(
8282
response, dict
8383
) else getattr(response, '@odata.deltaLink', '')
@@ -140,11 +140,8 @@ async def next(self) -> Optional[PageResult]:
140140
"""
141141
if self.current_page is not None and not self.current_page.odata_next_link:
142142
return None
143-
response = self.convert_to_page(await self.fetch_next_page())
144-
page: PageResult = PageResult(
145-
response.odata_next_link,
146-
response.get('value', []) if isinstance(response, dict) else []
147-
)
143+
response = await self.fetch_next_page()
144+
page: PageResult = PageResult(response.odata_next_link, response.value)
148145
return page
149146

150147
@staticmethod
@@ -180,7 +177,7 @@ def convert_to_page(response: Union[T, list, object]) -> PageResult:
180177
page: PageResult = PageResult(next_link, value)
181178
return page
182179

183-
async def fetch_next_page(self) -> dict:
180+
async def fetch_next_page(self) -> List[Parsable]:
184181
"""
185182
Fetches the next page of items from the server.
186183
Returns:

0 commit comments

Comments
 (0)