Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions tableauserverclient/server/pager.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from . import RequestOptions
from . import Sort


class Pager(object):
Expand All @@ -16,6 +17,11 @@ def __init__(self, endpoint, request_opts=None):
self._count = ((self._options.pagenumber - 1) * self._options.pagesize)
else:
self._count = 0
self._options = RequestOptions()

# Pager assumes deterministic order but solr doesn't guarantee sort order unless specified
if not self._options.sort:
self._options.sort.add(Sort(RequestOptions.Field.Name, RequestOptions.Direction.Asc))

def __iter__(self):
# Fetch the first page
Expand Down
8 changes: 4 additions & 4 deletions test/test_pager.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ def test_pager_with_options(self):
page_3 = f.read().decode('utf-8')
with requests_mock.mock() as m:
# Register Pager with some pages
m.get(self.baseurl + "?pageNumber=1&pageSize=1", text=page_1)
m.get(self.baseurl + "?pageNumber=2&pageSize=1", text=page_2)
m.get(self.baseurl + "?pageNumber=3&pageSize=1", text=page_3)
m.get(self.baseurl + "?pageNumber=1&pageSize=3", text=page_1)
m.get(self.baseurl + "?pageNumber=1&pageSize=1&sort=name:asc", complete_qs=True, text=page_1)
m.get(self.baseurl + "?pageNumber=2&pageSize=1&sort=name:asc", complete_qs=True, text=page_2)
m.get(self.baseurl + "?pageNumber=3&pageSize=1&sort=name:asc", complete_qs=True, text=page_3)
m.get(self.baseurl + "?pageNumber=1&pageSize=3&sort=name:asc", complete_qs=True, text=page_1)

# Starting on page 2 should get 2 out of 3
opts = TSC.RequestOptions(2, 1)
Expand Down