Repository navigation
UN-4224 [FIX] Fix GCS connector test connection on gcsfs 2026.x #2320
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
69 changes: 69 additions & 0 deletions
69
unstract/connectors/tests/filesystems/test_google_cloud_storage_fs.py
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| """GCS connector test-connection request shape (UN-4224). | ||
|
|
||
| From gcsfs 2026.x, ``info("/")`` sends ``GET b/`` without the project, which | ||
| GCS rejects with ``Required parameter: project`` (400) for every connector. | ||
| Test connection must list buckets with the configured project instead — the | ||
| same request gcsfs 2024.x sent for ``info("/")``. | ||
| """ | ||
|
|
||
| from typing import Any | ||
|
|
||
| import pytest | ||
| from gcsfs import core as gcsfs_core | ||
|
|
||
| # The core class explicitly: production runs it (storage_compat keeps gcsfs off | ||
| # the experimental ExtendedGcsFileSystem), and `gcsfs.GCSFileSystem` would | ||
| # depend on whether gcsfs was imported before storage_compat in this process. | ||
| from gcsfs.core import GCSFileSystem | ||
|
|
||
| from unstract.connectors.filesystems.google_cloud_storage.google_cloud_storage import ( | ||
| GoogleCloudStorageFS, | ||
| ) | ||
|
|
||
| _Calls = list[tuple[str, str, dict[str, Any]]] | ||
|
|
||
|
|
||
| @pytest.fixture | ||
| def gcs_requests(monkeypatch: pytest.MonkeyPatch) -> _Calls: | ||
| """Record gcsfs API requests and answer the way GCS does.""" | ||
| calls: _Calls = [] | ||
|
|
||
| async def fake_call( | ||
| self: GCSFileSystem, method: str, path: str, *args: Any, **kwargs: Any | ||
| ) -> dict[str, Any]: | ||
| calls.append((method, path, kwargs)) | ||
| if path.rstrip("/") == "b" and "project" not in kwargs: | ||
| # What GCS answers for a bucket listing that carries no project. | ||
| raise gcsfs_core.HttpError( | ||
| {"code": 400, "message": "Required parameter: project"} | ||
| ) | ||
| return {"kind": "storage#buckets", "items": [{"name": "bucket-a"}]} | ||
|
|
||
| monkeypatch.setattr(gcsfs_core.GCSFileSystem, "_call", fake_call) | ||
| return calls | ||
|
|
||
|
|
||
| def _connector(project: str) -> GoogleCloudStorageFS: | ||
| connector = GoogleCloudStorageFS({"project_id": project, "json_credentials": "{}"}) | ||
| # Bypass the lazy credential-backed client; only the request shape matters. | ||
| connector._gcs_fs = GCSFileSystem( | ||
| token="anon", project=project, skip_instance_cache=True | ||
| ) | ||
| return connector | ||
|
|
||
|
|
||
| def test_test_credentials_lists_buckets_with_the_configured_project( | ||
| gcs_requests: _Calls, | ||
| ) -> None: | ||
| assert _connector("my-project").test_credentials() is True | ||
|
|
||
| assert gcs_requests, "test_credentials made no request" | ||
| method, path, kwargs = gcs_requests[0] | ||
| assert (method, path) == ("GET", "b") | ||
| assert kwargs.get("project") == "my-project" | ||
| assert not any(c[1] == "b/" for c in gcs_requests), "sent the project-less GET b/" | ||
|
|
||
|
|
||
| def test_uses_the_core_gcsfs_class() -> None: | ||
| assert type(_connector("my-project")._gcs_fs) is GCSFileSystem | ||
| assert GCSFileSystem.__module__ == "gcsfs.core" | ||
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.