mirror of
https://github.com/status-im/PyGithub.git
synced 2026-08-31 10:51:14 +00:00
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:
@@ -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
|
||||
|
||||
@@ -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
Reference in New Issue
Block a user