Skip to content

Test resource keys against the real link-shared file - #459

Draft
shcheklein wants to merge 2 commits into
mainfrom
resource-key-tests-offline
Draft

shcheklein wants to merge 2 commits into
mainfrom
resource-key-tests-offline

Conversation

@shcheklein

@shcheklein shcheklein commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

Files shared by link before 2021 need a resource key: Drive serves them only when the request carries the X-Goog-Drive-Resource-Keys header. GoogleDriveFile sends it when the file's metadata has resourceKey.

Nothing checked that against real Drive.

  • Six tests in the live module used a mock transport. They sat in test_file.py, which runs with the live suite, but they went through a MagicMock that answered 200 only when the header was present. They checked the mock, not Drive. Each still made a real token request.
  • The two tests that used the real file were marked manual. The file is public, 0BxphPoRgwhnodHNjS3JESnFNS1E with key 0-vjzOveuin3fnf4LUlfsD3A. The tests were manual because they downloaded all 6 MB of it.

This replaces all eight:

  • Live, on the real file: one test reads its metadata and the first kilobyte of its content with the key (chunksize=1024). The bytes start with the ZIP signature, so Drive served the file itself.
  • Offline: metadata and download requests carry the header when the file has a 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

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>
Comment thread pydrive2/test/test_file.py Resolved
Comment thread pydrive2/test/test_file.py Resolved

@shcheklein shcheklein left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Comment thread pydrive2/test/test_file.py Resolved
Comment thread pydrive2/test/test_file.py Resolved
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>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants