Correctly deal when PaginatedList's data is a dict (#2084)

When calculating totalCount for a PaginatedList, if a Link header is not
in the returned data, we use len() to calculate the number of items.
PullRequest.get_review_requests() actually returns a dictionary, which
neatly defeats this naive method. Peer inside the dictionary in this
case, and add a test case.

Fixes #2053
This commit is contained in:
Steve Kowalik
2021-10-20 18:49:12 +11:00
committed by GitHub
parent 3f767649c8
commit 93b92cd2fc
3 changed files with 55 additions and 0 deletions
+2
View File
@@ -153,6 +153,8 @@ class PaginatedList(PaginatedListBase):
if data and "total_count" in data:
self.__totalCount = data["total_count"]
elif data:
if isinstance(data, dict):
data = data[self.__list_item]
self.__totalCount = len(data)
else:
self.__totalCount = 0
+9
View File
@@ -273,6 +273,15 @@ class PaginatedList(Framework.TestCase):
repos = self.g.get_repos()
self.assertEqual(0, repos.totalCount)
def testTotalCountWithDictionary(self):
# PullRequest.get_review_requests() actually returns a dictionary that
# we fudge into two lists, which means data is a dict, not a list.
# We should check the member, not data itself for totalCount.
pr = self.g.get_repo("PyGithub/PyGithub").get_pull(2078)
review_requests = pr.get_review_requests()
self.assertEqual(review_requests[0].totalCount, 0)
self.assertEqual(review_requests[1].totalCount, 0)
def testCustomPerPage(self):
self.assertEqual(self.g.per_page, 30)
self.g.per_page = 100
File diff suppressed because one or more lines are too long