Repository navigation
Test resource keys against the real link-shared file - #459
Draft
shcheklein wants to merge 2 commits into
Draft
shcheklein wants to merge 2 commits into
shcheklein wants to merge 2 commits into
Conversation
Six tests in the live module checked resource keys against a mock transport, and the two that used the real file were manual because they downloaded all 6 MB. Four live tests now read the real file's metadata and its first kilobyte, with and without its key. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
shcheklein
commented
Dec 3, 2026
shcheklein
commented
Dec 3, 2026
shcheklein
left a comment
Member
Author
There was a problem hiding this comment.
[AI generated — Copilot]
5-pass review summary: great cleanup (-165/+37 lines) — removes a fake MagicMock transport that still exchanged real OAuth tokens and replaces slow 6 MB manual tests with fast 1 KiB live tests. Two small improvements inline.
Drive serves a link-shared file without its key to an account that opened it recently, and the CI account opens it on every run, so the live 404 checks depended on account history. One live test now opens the real file with its key, and an offline test checks that metadata and download requests carry the header only when the file has a key. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
There was a problem hiding this comment.
🟢 Approval recommended
No active review issues were identified in the test-only resource-key coverage changes.
No open issues 🎉
What changed in this PR
This test-only PR separates live Drive resource-key validation from offline request-header checks.
Changes:
- Replaces mocked and manual live-module tests with one real-file test that fetches metadata and 1 KB of ZIP content.
- Adds offline checks for resource-key header presence and absence.
- Removes the obsolete mock authentication helper and imports.
| File | Description |
|---|---|
| pydrive2/test/test_files_unit.py | Adds parameterized resource-key header checks for metadata and downloads. |
| pydrive2/test/test_file.py | Consolidates resource-key tests into a bounded live download and removes mock scaffolding. |
Review effort: Balanced
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Files shared by link before 2021 need a resource key: Drive serves them only when the request carries the
X-Goog-Drive-Resource-Keysheader.GoogleDriveFilesends it when the file's metadata hasresourceKey.Nothing checked that against real Drive.
test_file.py, which runs with the live suite, but they went through aMagicMockthat answered 200 only when the header was present. They checked the mock, not Drive. Each still made a real token request.0BxphPoRgwhnodHNjS3JESnFNS1Ewith key0-vjzOveuin3fnf4LUlfsD3A. The tests were manual because they downloaded all 6 MB of it.This replaces all eight:
chunksize=1024). The bytes start with the ZIP signature, so Drive served the file itself.resourceKey, and only then.The "without the key" case cannot be live. Drive serves a link-shared file without its key to an account that has opened it recently, and the CI account opens this file on every run, so a live 404 check would depend on the account's history. That is the one answer Drive cannot reliably be made to send, so it is checked against a mock.
Test-only change: the mock helper and its imports go too. The offline suite passes with the current google-auth and with 2.15.0 (540 passed). The new offline test fails when the header is not sent.
One risk: the live test depends on a file outside this project. It has been used for these tests since resource keys were added. If it ever disappears, the live test fails; the offline test still checks the header.
🤖 Generated with Claude Code