bcbd1bdb22
Test (Python) / test-python-gate (push) Blocked by required conditions
Test (TypeScript) / test-typescript-gate (push) Blocked by required conditions
CLI exit codes / cli-gate (push) Blocked by required conditions
Test (Install) / test-install-gate (push) Blocked by required conditions
Integ / integ-gate (push) Blocked by required conditions
CLI exit codes / Python CLI (push) Waiting to run
Integ / changes (push) Has been skipped
Test (Install) / python-minimal (3.11) (push) Waiting to run
Test (Install) / python-minimal (3.12) (push) Waiting to run
Test (Install) / python-extra (chroma, mirage.resource.chroma) (push) Waiting to run
Integ / integ-ts (push) Waiting to run
Integ / integ (push) Waiting to run
Test (Install) / python-extra (deepagents, mirage.agents.langchain) (push) Waiting to run
Integ / integ-database (push) Waiting to run
Test (Install) / python-extra (email, mirage.resource.email) (push) Waiting to run
Test (Install) / python-extra (hdf5, mirage.core.filetype.hdf5) (push) Waiting to run
Integ / integ-ssh (push) Waiting to run
Pre-commit / pre-commit (push) Failing after 1s
CLI exit codes / changes (push) Has been skipped
Test (Install) / changes (push) Has been skipped
CLI exit codes / TypeScript CLI (push) Waiting to run
CLI exit codes / Cross-language snapshot interop (push) Waiting to run
Test (Install) / python-extra (agno, mirage.agents.agno) (push) Waiting to run
Test (Install) / python-extra (databricks, mirage.resource.databricks_volume) (push) Waiting to run
Test (Python) / changes (push) Has been skipped
Integ / integ-database-ts (push) Waiting to run
Test (Install) / python-extra (fuse, mirage.fuse.mount) (push) Waiting to run
Integ / integ-data (push) Waiting to run
Test (Install) / python-extra (lancedb, mirage.resource.lancedb) (push) Waiting to run
Test (Python) / test (push) Waiting to run
Integ / integ-fuse (push) Waiting to run
Test (Install) / python-extra (langfuse, mirage.resource.langfuse) (push) Waiting to run
Test (Python) / import-isolation (deepagents, openai, mirage.agents.openai_agents) (push) Waiting to run
Test (Python) / audit (push) Waiting to run
Test (Install) / python-extra (hf, mirage.resource.hf_buckets) (push) Waiting to run
Integ / integ-ssh-ts (push) Waiting to run
Test (Install) / python-extra (mongodb, mirage.resource.mongodb) (push) Waiting to run
Test (Python) / import-isolation (deepagents, pydantic-ai, mirage.agents.pydantic_ai) (push) Waiting to run
Test (TypeScript) / changes (push) Has been skipped
Test (Install) / python-extra (nextcloud, mirage.resource.nextcloud) (push) Waiting to run
Test (Install) / python-extra (openai, mirage.agents.openai_agents) (push) Waiting to run
Test (Install) / python-extra (openhands, mirage.agents.openhands, 3.12) (push) Waiting to run
Test (Install) / python-extra (parquet, mirage.core.filetype.parquet) (push) Waiting to run
Test (TypeScript) / test (push) Waiting to run
Test (Install) / python-extra (pdf, mirage.core.filetype.pdf) (push) Waiting to run
Test (TypeScript) / python-fs-shim (push) Waiting to run
Test (Install) / python-extra (postgres, mirage.resource.postgres) (push) Waiting to run
Test (Install) / python-extra (pydantic-ai, mirage.agents.pydantic_ai) (push) Waiting to run
Test (Install) / python-extra (qdrant, mirage.resource.qdrant) (push) Waiting to run
Test (Install) / python-extra (redis, mirage.resource.redis) (push) Waiting to run
Test (Install) / python-extra (s3, mirage.resource.s3) (push) Waiting to run
Test (Install) / python-extra (ssh, mirage.resource.ssh) (push) Waiting to run
Test (Install) / ts-minimal (push) Waiting to run
299 lines
8.7 KiB
Python
299 lines
8.7 KiB
Python
# ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========
|
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
# you may not use this file except in compliance with the License.
|
|
# You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
# ========= Copyright 2026 @ Strukto.AI All Rights Reserved. =========
|
|
|
|
from unittest.mock import AsyncMock, patch
|
|
|
|
import pytest
|
|
|
|
from mirage.core.google._client import TokenManager
|
|
from mirage.core.google.config import GoogleConfig
|
|
from mirage.core.google.drive import (delete_file, download_file,
|
|
download_file_stream, list_all_files,
|
|
list_files, list_shared_drives)
|
|
|
|
|
|
@pytest.fixture
|
|
def config():
|
|
return GoogleConfig(
|
|
client_id="test-id",
|
|
client_secret="test-secret",
|
|
refresh_token="test-refresh",
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
def token_manager(config):
|
|
mgr = TokenManager(config)
|
|
mgr._access_token = "fake-token"
|
|
mgr._expires_at = 9999999999
|
|
return mgr
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_list_files(token_manager):
|
|
mock_response = {
|
|
"files": [
|
|
{
|
|
"id": "f1",
|
|
"name": "doc.txt",
|
|
"mimeType": "text/plain"
|
|
},
|
|
{
|
|
"id": "f2",
|
|
"name": "sheet",
|
|
"mimeType": "application/vnd.google-apps.spreadsheet"
|
|
},
|
|
],
|
|
}
|
|
with patch(
|
|
"mirage.core.google.drive.google_get",
|
|
new_callable=AsyncMock,
|
|
return_value=mock_response,
|
|
) as mock_get:
|
|
result = await list_files(token_manager, folder_id="folder123")
|
|
assert len(result) == 2
|
|
assert result[0]["id"] == "f1"
|
|
call_kwargs = mock_get.call_args
|
|
params = call_kwargs.kwargs["params"]
|
|
assert "'folder123' in parents" in params["q"]
|
|
assert "trashed=false" in params["q"]
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_list_files_shared_drive_sets_corpus_params(token_manager):
|
|
with patch(
|
|
"mirage.core.google.drive.google_get",
|
|
new_callable=AsyncMock,
|
|
return_value={"files": []},
|
|
) as mock_get:
|
|
await list_files(token_manager,
|
|
folder_id="folder123",
|
|
drive_id="drive123")
|
|
|
|
params = mock_get.call_args.kwargs["params"]
|
|
assert params["corpora"] == "drive"
|
|
assert params["driveId"] == "drive123"
|
|
assert params["includeItemsFromAllDrives"] == "true"
|
|
assert params["supportsAllDrives"] == "true"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_list_shared_drives_paginates(token_manager):
|
|
responses = [
|
|
{
|
|
"drives": [{
|
|
"id": "drive1",
|
|
"name": "Team"
|
|
}],
|
|
"nextPageToken": "next",
|
|
},
|
|
{
|
|
"drives": [{
|
|
"id": "drive2",
|
|
"name": "Projects"
|
|
}],
|
|
},
|
|
]
|
|
with patch(
|
|
"mirage.core.google.drive.google_get",
|
|
new_callable=AsyncMock,
|
|
side_effect=responses,
|
|
) as mock_get:
|
|
result = await list_shared_drives(token_manager)
|
|
|
|
assert result == [
|
|
{
|
|
"id": "drive1",
|
|
"name": "Team"
|
|
},
|
|
{
|
|
"id": "drive2",
|
|
"name": "Projects"
|
|
},
|
|
]
|
|
assert mock_get.call_count == 2
|
|
assert "pageToken" not in mock_get.call_args_list[0].kwargs["params"]
|
|
assert mock_get.call_args_list[1].kwargs["params"]["pageToken"] == "next"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_list_all_files(token_manager):
|
|
page1 = {
|
|
"files": [{
|
|
"id": "f1",
|
|
"name": "a.txt",
|
|
"mimeType": "text/plain"
|
|
}],
|
|
"nextPageToken": "token2",
|
|
}
|
|
page2 = {
|
|
"files": [{
|
|
"id": "f2",
|
|
"name": "b.txt",
|
|
"mimeType": "text/plain"
|
|
}],
|
|
}
|
|
with patch(
|
|
"mirage.core.google.drive.google_get",
|
|
new_callable=AsyncMock,
|
|
side_effect=[page1, page2],
|
|
):
|
|
result = await list_all_files(token_manager)
|
|
assert len(result) == 2
|
|
assert result[0]["id"] == "f1"
|
|
assert result[1]["id"] == "f2"
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_download_file(token_manager):
|
|
content = b"file content bytes"
|
|
with patch(
|
|
"mirage.core.google.drive.google_get_bytes",
|
|
new_callable=AsyncMock,
|
|
return_value=content,
|
|
) as mock_get:
|
|
result = await download_file(token_manager, "file123")
|
|
assert result == content
|
|
assert "supportsAllDrives=true" in mock_get.call_args.args[1]
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_download_file_stream(token_manager):
|
|
chunks = [b"chunk1", b"chunk2", b"chunk3"]
|
|
|
|
async def mock_stream(*args, **kwargs):
|
|
for chunk in chunks:
|
|
yield chunk
|
|
|
|
with patch(
|
|
"mirage.core.google.drive.google_get_stream",
|
|
side_effect=mock_stream,
|
|
) as mock_get:
|
|
result = b""
|
|
async for chunk in download_file_stream(token_manager, "file123"):
|
|
result += chunk
|
|
assert result == b"chunk1chunk2chunk3"
|
|
assert "supportsAllDrives=true" in mock_get.call_args.args[1]
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_download_file_stream_empty(token_manager):
|
|
|
|
async def mock_stream(*args, **kwargs):
|
|
return
|
|
yield
|
|
|
|
with patch(
|
|
"mirage.core.google.drive.google_get_stream",
|
|
side_effect=mock_stream,
|
|
):
|
|
result = b""
|
|
async for chunk in download_file_stream(token_manager, "file123"):
|
|
result += chunk
|
|
assert result == b""
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_delete_file_supports_shared_drives(token_manager):
|
|
with patch(
|
|
"mirage.core.google.drive.google_delete",
|
|
new_callable=AsyncMock,
|
|
) as mock_delete:
|
|
await delete_file(token_manager, "file123")
|
|
|
|
assert "supportsAllDrives=true" in mock_delete.call_args.args[1]
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_list_all_files_with_modified_range():
|
|
captured = {}
|
|
|
|
async def fake_get(token_manager, url, params=None):
|
|
captured["params"] = params
|
|
return {"files": []}
|
|
|
|
with patch("mirage.core.google.drive.google_get", new=fake_get):
|
|
await list_all_files(
|
|
token_manager=None,
|
|
mime_type="application/vnd.google-apps.document",
|
|
modified_after="2026-05-01T00:00:00Z",
|
|
modified_before="2026-06-01T00:00:00Z",
|
|
)
|
|
|
|
q = captured["params"]["q"]
|
|
assert "modifiedTime >= '2026-05-01T00:00:00Z'" in q
|
|
assert "modifiedTime < '2026-06-01T00:00:00Z'" in q
|
|
assert "mimeType='application/vnd.google-apps.document'" in q
|
|
assert "trashed=false" in q
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_list_all_files_without_range_omits_clauses():
|
|
captured = {}
|
|
|
|
async def fake_get(token_manager, url, params=None):
|
|
captured["params"] = params
|
|
return {"files": []}
|
|
|
|
with patch("mirage.core.google.drive.google_get", new=fake_get):
|
|
await list_all_files(token_manager=None)
|
|
|
|
q = captured["params"].get("q")
|
|
if q is None:
|
|
return
|
|
assert "modifiedTime" not in q
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_list_files_with_modified_range():
|
|
captured = {}
|
|
|
|
async def fake_get(token_manager, url, params=None):
|
|
captured["params"] = params
|
|
return {"files": []}
|
|
|
|
with patch("mirage.core.google.drive.google_get", new=fake_get):
|
|
await list_files(
|
|
token_manager=None,
|
|
folder_id="root",
|
|
modified_after="2026-05-01T00:00:00Z",
|
|
)
|
|
|
|
q = captured["params"]["q"]
|
|
assert "'root' in parents" in q
|
|
assert "modifiedTime >= '2026-05-01T00:00:00Z'" in q
|
|
assert "modifiedTime <" not in q
|
|
|
|
|
|
@pytest.mark.asyncio
|
|
async def test_list_files_with_full_modified_range():
|
|
captured = {}
|
|
|
|
async def fake_get(token_manager, url, params=None):
|
|
captured["params"] = params
|
|
return {"files": []}
|
|
|
|
with patch("mirage.core.google.drive.google_get", new=fake_get):
|
|
await list_files(
|
|
token_manager=None,
|
|
folder_id="root",
|
|
modified_after="2026-05-01T00:00:00Z",
|
|
modified_before="2026-06-01T00:00:00Z",
|
|
)
|
|
|
|
q = captured["params"]["q"]
|
|
assert "'root' in parents" in q
|
|
assert "modifiedTime >= '2026-05-01T00:00:00Z'" in q
|
|
assert "modifiedTime < '2026-06-01T00:00:00Z'" in q
|