(self)
| 466 | self.assertEqual(len(requests), 0) |
| 467 | |
| 468 | def testReversedWithFirstPage(self): |
| 469 | # this is all lazy, no requests fired |
| 470 | with self.captureRequests() as requests: |
| 471 | repo = self.g.get_repo("PyGithub/PyGithub", lazy=True) |
| 472 | commit = repo.get_commit("e359b83a04e8f34bedab0f2180169012d238a135", commit_files_per_page=3) |
| 473 | # repo is lazy, so this commit is also lazy, here we test with an eager (fetched) commit |
| 474 | commit.complete() |
| 475 | files = commit.files |
| 476 | self.assertListKeyEqual( |
| 477 | requests, |
| 478 | lambda r: r.url, |
| 479 | ["/repos/PyGithub/PyGithub/commits/e359b83a04e8f34bedab0f2180169012d238a135?page=1&per_page=3"], |
| 480 | ) |
| 481 | |
| 482 | # reversing files does not fire a request because there is a last Link header in the first response |
| 483 | with self.captureRequests() as requests: |
| 484 | files = files.reversed |
| 485 | self.assertEqual(len(requests), 0) |
| 486 | |
| 487 | # consuming the first page of the reversed files fetches the "last" URL |
| 488 | with self.captureRequests() as requests: |
| 489 | self.assertEqual(files[0].filename, "tests/test_release_notes.yml") |
| 490 | self.assertListKeyEqual( |
| 491 | requests, |
| 492 | lambda r: r.url, |
| 493 | ["/repositories/3544490/commits/e359b83a04e8f34bedab0f2180169012d238a135?page=3&per_page=3"], |
| 494 | ) |
| 495 | |
| 496 | # consuming items of the second page fetches the second page |
| 497 | with self.captureRequests() as requests: |
| 498 | self.assertEqual(files[1].filename, "tests/Repository.py") |
| 499 | self.assertListKeyEqual( |
| 500 | requests, |
| 501 | lambda r: r.url, |
| 502 | ["/repositories/3544490/commits/e359b83a04e8f34bedab0f2180169012d238a135?page=2&per_page=3"], |
| 503 | ) |
| 504 | # consuming further items of the second page does not fire a request |
| 505 | with self.captureRequests() as requests: |
| 506 | self.assertEqual( |
| 507 | files[2].filename, "tests/ReplayData/Repository.testGenerateReleaseNotesWithAllArguments.txt" |
| 508 | ) |
| 509 | self.assertEqual(files[3].filename, "tests/ReplayData/Repository.testGenerateReleaseNotes.txt") |
| 510 | self.assertEqual(len(requests), 0) |
| 511 | |
| 512 | # consuming items of the last page fetches the that page |
| 513 | with self.captureRequests() as requests: |
| 514 | self.assertEqual(files[4].filename, "pyproject.toml") |
| 515 | self.assertEqual(files[5].filename, "github/Repository.py") |
| 516 | self.assertEqual(files[6].filename, "github/GeneratedReleaseNotes.py") |
| 517 | self.assertListKeyEqual( |
| 518 | requests, |
| 519 | lambda r: r.url, |
| 520 | ["/repositories/3544490/commits/e359b83a04e8f34bedab0f2180169012d238a135?page=1&per_page=3"], |
| 521 | ) |
| 522 | |
| 523 | def testReversedWithFirstSinglePage(self): |
| 524 | # fetching the commit also fetches the fist page of files |
nothing calls this directly
no test coverage detected