Skip to content

Commit 4cf1916

Browse files
authored
Merge pull request #1449 from jorwoods/jorwoods/fix_pager_typing
fix: Pager typing
2 parents 678d46a + bb4ba5a commit 4cf1916

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

tableauserverclient/server/pager.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
11
import copy
22
from functools import partial
3-
from typing import Generic, Iterable, Iterator, List, Optional, Protocol, Tuple, TypeVar, Union, runtime_checkable
3+
from typing import Iterable, Iterator, List, Optional, Protocol, Tuple, TypeVar, Union, runtime_checkable
44

55
from tableauserverclient.models.pagination_item import PaginationItem
66
from tableauserverclient.server.request_options import RequestOptions
77

88

99
T = TypeVar("T")
10-
ReturnType = Tuple[List[T], PaginationItem]
1110

1211

1312
@runtime_checkable
14-
class Endpoint(Protocol):
15-
def get(self, req_options: Optional[RequestOptions], **kwargs) -> ReturnType:
13+
class Endpoint(Protocol[T]):
14+
def get(self, req_options: Optional[RequestOptions]) -> Tuple[List[T], PaginationItem]:
1615
...
1716

1817

1918
@runtime_checkable
20-
class CallableEndpoint(Protocol):
21-
def __call__(self, __req_options: Optional[RequestOptions], **kwargs) -> ReturnType:
19+
class CallableEndpoint(Protocol[T]):
20+
def __call__(self, __req_options: Optional[RequestOptions], **kwargs) -> Tuple[List[T], PaginationItem]:
2221
...
2322

2423

@@ -33,7 +32,7 @@ class Pager(Iterable[T]):
3332

3433
def __init__(
3534
self,
36-
endpoint: Union[CallableEndpoint, Endpoint],
35+
endpoint: Union[CallableEndpoint[T], Endpoint[T]],
3736
request_opts: Optional[RequestOptions] = None,
3837
**kwargs,
3938
) -> None:

test/test_pager.py

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
TEST_ASSET_DIR = os.path.join(os.path.dirname(__file__), "assets")
1111

12+
GET_VIEW_XML = os.path.join(TEST_ASSET_DIR, "view_get.xml")
1213
GET_XML_PAGE1 = os.path.join(TEST_ASSET_DIR, "workbook_get_page_1.xml")
1314
GET_XML_PAGE2 = os.path.join(TEST_ASSET_DIR, "workbook_get_page_2.xml")
1415
GET_XML_PAGE3 = os.path.join(TEST_ASSET_DIR, "workbook_get_page_3.xml")
@@ -35,7 +36,7 @@ def setUp(self):
3536

3637
self.baseurl = self.server.workbooks.baseurl
3738

38-
def test_pager_with_no_options(self):
39+
def test_pager_with_no_options(self) -> None:
3940
with open(GET_XML_PAGE1, "rb") as f:
4041
page_1 = f.read().decode("utf-8")
4142
with open(GET_XML_PAGE2, "rb") as f:
@@ -61,7 +62,7 @@ def test_pager_with_no_options(self):
6162
self.assertEqual(wb2.name, "Page2Workbook")
6263
self.assertEqual(wb3.name, "Page3Workbook")
6364

64-
def test_pager_with_options(self):
65+
def test_pager_with_options(self) -> None:
6566
with open(GET_XML_PAGE1, "rb") as f:
6667
page_1 = f.read().decode("utf-8")
6768
with open(GET_XML_PAGE2, "rb") as f:
@@ -102,14 +103,22 @@ def test_pager_with_options(self):
102103
wb3 = workbooks.pop()
103104
self.assertEqual(wb3.name, "Page3Workbook")
104105

105-
def test_pager_with_env_var(self):
106+
def test_pager_with_env_var(self) -> None:
106107
with set_env(TSC_PAGE_SIZE="1000"):
107108
assert config.PAGE_SIZE == 1000
108109
loop = TSC.Pager(self.server.workbooks)
109110
assert loop._options.pagesize == 1000
110111

111-
def test_queryset_with_env_var(self):
112+
def test_queryset_with_env_var(self) -> None:
112113
with set_env(TSC_PAGE_SIZE="1000"):
113114
assert config.PAGE_SIZE == 1000
114115
loop = self.server.workbooks.all()
115116
assert loop.request_options.pagesize == 1000
117+
118+
def test_pager_view(self) -> None:
119+
with open(GET_VIEW_XML, "rb") as f:
120+
view_xml = f.read().decode("utf-8")
121+
with requests_mock.mock() as m:
122+
m.get(self.server.views.baseurl, text=view_xml)
123+
for view in TSC.Pager(self.server.views):
124+
assert view.name is not None

0 commit comments

Comments
 (0)