MCPcopy
hub / github.com/PyGithub/PyGithub / testReversedWithFirstSinglePage

Method testReversedWithFirstSinglePage

tests/PaginatedList.py:523–553  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

521 )
522
523 def testReversedWithFirstSinglePage(self):
524 # fetching the commit also fetches the fist page of files
525 with self.captureRequests() as requests:
526 repo = self.g.get_repo("PyGithub/PyGithub", lazy=True)
527 commit = repo.get_commit("f5f9756a1dd52a53820cc54927abb34725377987", commit_files_per_page=3)
528 # repo is lazy, so this commit is also lazy, here we test with an eager (fetched) commit
529 commit.complete()
530 files = commit.files
531 # with a single page we by now know the total count without firing a request
532 self.assertEqual(files.totalCount, 3)
533 self.assertListKeyEqual(
534 requests,
535 lambda r: r.url,
536 [
537 "/repos/PyGithub/PyGithub/commits/f5f9756a1dd52a53820cc54927abb34725377987?page=1&per_page=3",
538 ],
539 )
540
541 # reversing files fires another request because there were no Link headers in the first response
542 with self.captureRequests() as requests:
543 files = files.reversed
544 self.assertListKeyEqual(
545 requests, lambda r: r.url, ["/repos/PyGithub/PyGithub/commits/f5f9756a1dd52a53820cc54927abb34725377987"]
546 )
547
548 # consuming the first page of files should not fire a request
549 with self.captureRequests() as requests:
550 self.assertEqual(files[0].filename, "tests/GithubObject.py")
551 self.assertEqual(files[1].filename, "github/GithubObject.py")
552 self.assertEqual(files[2].filename, "github/GithubApp.py")
553 self.assertEqual(len(requests), 0)
554
555 def testNoFirstPage(self):
556 self.assertFalse(next(iter(self.list), None))

Callers

nothing calls this directly

Calls 5

captureRequestsMethod · 0.80
get_commitMethod · 0.80
completeMethod · 0.80
assertListKeyEqualMethod · 0.80
get_repoMethod · 0.45

Tested by

no test coverage detected