Skip to content

Commit

Permalink
Correctly deal when PaginatedList's data is a dict (#2084)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
s-t-e-v-e-n-k committed Oct 20, 2021
1 parent 3f76764 commit 93b92cd
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 0 deletions.
2 changes: 2 additions & 0 deletions github/PaginatedList.py
Expand Up @@ -153,6 +153,8 @@ def totalCount(self):
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
Expand Down
9 changes: 9 additions & 0 deletions tests/PaginatedList.py
Expand Up @@ -273,6 +273,15 @@ def testTotalCountWithNoLastPage(self):
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
Expand Down

0 comments on commit 93b92cd

Please sign in to comment.