Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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