chore: import upstream snapshot with attribution
Integ / changes (push) Has been skipped
Pre-commit / pre-commit (push) Failing after 1s
CLI exit codes / changes (push) Has been skipped
Test (Install) / changes (push) Has been skipped
Test (Python) / changes (push) Has been skipped
Test (TypeScript) / changes (push) Has been skipped
CLI exit codes / cli-gate (push) Has been cancelled
Test (Install) / test-install-gate (push) Has been cancelled
Integ / integ-gate (push) Has been cancelled
Test (Python) / test-python-gate (push) Has been cancelled
Test (TypeScript) / test-typescript-gate (push) Has been cancelled
Test (Install) / python-minimal (3.12) (push) Has been cancelled
Test (Install) / python-minimal (3.11) (push) Has been cancelled
Test (Install) / python-extra (agno, mirage.agents.agno) (push) Has been cancelled
Test (Install) / python-extra (chroma, mirage.resource.chroma) (push) Has been cancelled
Test (Install) / python-extra (pdf, mirage.core.filetype.pdf) (push) Has been cancelled
Integ / integ (push) Has been cancelled
Integ / integ-database (push) Has been cancelled
Integ / integ-database-ts (push) Has been cancelled
Integ / integ-data (push) Has been cancelled
Integ / integ-ssh (push) Has been cancelled
Integ / integ-ssh-ts (push) Has been cancelled
Test (Python) / audit (push) Has been cancelled
Test (TypeScript) / test (push) Has been cancelled
Test (TypeScript) / python-fs-shim (push) Has been cancelled
CLI exit codes / Python CLI (push) Has been cancelled
CLI exit codes / TypeScript CLI (push) Has been cancelled
CLI exit codes / Cross-language snapshot interop (push) Has been cancelled
Test (Python) / test (push) Has been cancelled
Test (Python) / import-isolation (deepagents, openai, mirage.agents.openai_agents) (push) Has been cancelled
Test (Python) / import-isolation (deepagents, pydantic-ai, mirage.agents.pydantic_ai) (push) Has been cancelled
Integ / integ-ts (push) Has been cancelled
Integ / integ-fuse (push) Has been cancelled
Test (Install) / python-extra (databricks, mirage.resource.databricks_volume) (push) Has been cancelled
Test (Install) / python-extra (deepagents, mirage.agents.langchain) (push) Has been cancelled
Test (Install) / python-extra (email, mirage.resource.email) (push) Has been cancelled
Test (Install) / python-extra (fuse, mirage.fuse.mount) (push) Has been cancelled
Test (Install) / python-extra (hdf5, mirage.core.filetype.hdf5) (push) Has been cancelled
Test (Install) / python-extra (hf, mirage.resource.hf_buckets) (push) Has been cancelled
Test (Install) / python-extra (lancedb, mirage.resource.lancedb) (push) Has been cancelled
Test (Install) / python-extra (langfuse, mirage.resource.langfuse) (push) Has been cancelled
Test (Install) / python-extra (mongodb, mirage.resource.mongodb) (push) Has been cancelled
Test (Install) / python-extra (nextcloud, mirage.resource.nextcloud) (push) Has been cancelled
Test (Install) / python-extra (openai, mirage.agents.openai_agents) (push) Has been cancelled
Test (Install) / python-extra (openhands, mirage.agents.openhands, 3.12) (push) Has been cancelled
Test (Install) / python-extra (parquet, mirage.core.filetype.parquet) (push) Has been cancelled
Test (Install) / python-extra (postgres, mirage.resource.postgres) (push) Has been cancelled
Test (Install) / python-extra (pydantic-ai, mirage.agents.pydantic_ai) (push) Has been cancelled
Test (Install) / python-extra (qdrant, mirage.resource.qdrant) (push) Has been cancelled
Test (Install) / python-extra (redis, mirage.resource.redis) (push) Has been cancelled
Test (Install) / python-extra (s3, mirage.resource.s3) (push) Has been cancelled
Test (Install) / python-extra (ssh, mirage.resource.ssh) (push) Has been cancelled
Test (Install) / ts-minimal (push) Has been cancelled
Integ / changes (push) Has been skipped
Pre-commit / pre-commit (push) Failing after 1s
CLI exit codes / changes (push) Has been skipped
Test (Install) / changes (push) Has been skipped
Test (Python) / changes (push) Has been skipped
Test (TypeScript) / changes (push) Has been skipped
CLI exit codes / cli-gate (push) Has been cancelled
Test (Install) / test-install-gate (push) Has been cancelled
Integ / integ-gate (push) Has been cancelled
Test (Python) / test-python-gate (push) Has been cancelled
Test (TypeScript) / test-typescript-gate (push) Has been cancelled
Test (Install) / python-minimal (3.12) (push) Has been cancelled
Test (Install) / python-minimal (3.11) (push) Has been cancelled
Test (Install) / python-extra (agno, mirage.agents.agno) (push) Has been cancelled
Test (Install) / python-extra (chroma, mirage.resource.chroma) (push) Has been cancelled
Test (Install) / python-extra (pdf, mirage.core.filetype.pdf) (push) Has been cancelled
Integ / integ (push) Has been cancelled
Integ / integ-database (push) Has been cancelled
Integ / integ-database-ts (push) Has been cancelled
Integ / integ-data (push) Has been cancelled
Integ / integ-ssh (push) Has been cancelled
Integ / integ-ssh-ts (push) Has been cancelled
Test (Python) / audit (push) Has been cancelled
Test (TypeScript) / test (push) Has been cancelled
Test (TypeScript) / python-fs-shim (push) Has been cancelled
CLI exit codes / Python CLI (push) Has been cancelled
CLI exit codes / TypeScript CLI (push) Has been cancelled
CLI exit codes / Cross-language snapshot interop (push) Has been cancelled
Test (Python) / test (push) Has been cancelled
Test (Python) / import-isolation (deepagents, openai, mirage.agents.openai_agents) (push) Has been cancelled
Test (Python) / import-isolation (deepagents, pydantic-ai, mirage.agents.pydantic_ai) (push) Has been cancelled
Integ / integ-ts (push) Has been cancelled
Integ / integ-fuse (push) Has been cancelled
Test (Install) / python-extra (databricks, mirage.resource.databricks_volume) (push) Has been cancelled
Test (Install) / python-extra (deepagents, mirage.agents.langchain) (push) Has been cancelled
Test (Install) / python-extra (email, mirage.resource.email) (push) Has been cancelled
Test (Install) / python-extra (fuse, mirage.fuse.mount) (push) Has been cancelled
Test (Install) / python-extra (hdf5, mirage.core.filetype.hdf5) (push) Has been cancelled
Test (Install) / python-extra (hf, mirage.resource.hf_buckets) (push) Has been cancelled
Test (Install) / python-extra (lancedb, mirage.resource.lancedb) (push) Has been cancelled
Test (Install) / python-extra (langfuse, mirage.resource.langfuse) (push) Has been cancelled
Test (Install) / python-extra (mongodb, mirage.resource.mongodb) (push) Has been cancelled
Test (Install) / python-extra (nextcloud, mirage.resource.nextcloud) (push) Has been cancelled
Test (Install) / python-extra (openai, mirage.agents.openai_agents) (push) Has been cancelled
Test (Install) / python-extra (openhands, mirage.agents.openhands, 3.12) (push) Has been cancelled
Test (Install) / python-extra (parquet, mirage.core.filetype.parquet) (push) Has been cancelled
Test (Install) / python-extra (postgres, mirage.resource.postgres) (push) Has been cancelled
Test (Install) / python-extra (pydantic-ai, mirage.agents.pydantic_ai) (push) Has been cancelled
Test (Install) / python-extra (qdrant, mirage.resource.qdrant) (push) Has been cancelled
Test (Install) / python-extra (redis, mirage.resource.redis) (push) Has been cancelled
Test (Install) / python-extra (s3, mirage.resource.s3) (push) Has been cancelled
Test (Install) / python-extra (ssh, mirage.resource.ssh) (push) Has been cancelled
Test (Install) / ts-minimal (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
# ========= 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. =========
|
||||
@@ -0,0 +1,149 @@
|
||||
# ========= 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 patch
|
||||
|
||||
import pytest
|
||||
|
||||
from mirage.core.google._client import refresh_access_token
|
||||
from mirage.core.google.config import GoogleConfig
|
||||
from mirage.resource.gdocs.config import GDocsConfig
|
||||
from mirage.resource.gdrive.config import GoogleDriveConfig
|
||||
from mirage.resource.secrets import reveal_secret
|
||||
|
||||
|
||||
def test_google_config_creation():
|
||||
config = GoogleConfig(
|
||||
client_id="id",
|
||||
client_secret="secret",
|
||||
refresh_token="token",
|
||||
)
|
||||
assert config.client_id == "id"
|
||||
assert reveal_secret(config.client_secret) == "secret"
|
||||
assert reveal_secret(config.refresh_token) == "token"
|
||||
|
||||
|
||||
def test_google_config_omits_client_secret_for_pkce():
|
||||
# Browser PKCE flows construct GoogleConfig without a secret.
|
||||
config = GoogleConfig(client_id="id", refresh_token="token")
|
||||
assert config.client_id == "id"
|
||||
assert config.client_secret is None
|
||||
assert reveal_secret(config.refresh_token) == "token"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_refresh_access_token_omits_client_secret_when_absent():
|
||||
# PKCE clients refresh with just (client_id, refresh_token, grant_type).
|
||||
# Sending an empty/None client_secret would be rejected by Google's
|
||||
# token endpoint for public clients, so make sure we don't include it.
|
||||
captured: dict = {}
|
||||
|
||||
class _FakeResp:
|
||||
|
||||
async def __aenter__(self):
|
||||
return self
|
||||
|
||||
async def __aexit__(self, *_):
|
||||
return None
|
||||
|
||||
def raise_for_status(self):
|
||||
return None
|
||||
|
||||
async def json(self):
|
||||
return {"access_token": "atk", "expires_in": 3600}
|
||||
|
||||
class _FakeSession:
|
||||
|
||||
async def __aenter__(self):
|
||||
return self
|
||||
|
||||
async def __aexit__(self, *_):
|
||||
return None
|
||||
|
||||
def post(self, url, data):
|
||||
captured["url"] = url
|
||||
captured["data"] = data
|
||||
return _FakeResp()
|
||||
|
||||
with patch("mirage.core.google._client.aiohttp.ClientSession",
|
||||
return_value=_FakeSession()):
|
||||
config = GoogleConfig(client_id="id", refresh_token="rt")
|
||||
token, expires = await refresh_access_token(config)
|
||||
assert token == "atk"
|
||||
assert expires == 3600
|
||||
assert "client_secret" not in captured["data"]
|
||||
assert captured["data"]["client_id"] == "id"
|
||||
assert captured["data"]["refresh_token"] == "rt"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_refresh_access_token_includes_client_secret_when_present():
|
||||
# Backwards compat: Node-style configs with a real secret keep working.
|
||||
captured: dict = {}
|
||||
|
||||
class _FakeResp:
|
||||
|
||||
async def __aenter__(self):
|
||||
return self
|
||||
|
||||
async def __aexit__(self, *_):
|
||||
return None
|
||||
|
||||
def raise_for_status(self):
|
||||
return None
|
||||
|
||||
async def json(self):
|
||||
return {"access_token": "atk", "expires_in": 3600}
|
||||
|
||||
class _FakeSession:
|
||||
|
||||
async def __aenter__(self):
|
||||
return self
|
||||
|
||||
async def __aexit__(self, *_):
|
||||
return None
|
||||
|
||||
def post(self, url, data):
|
||||
captured["data"] = data
|
||||
return _FakeResp()
|
||||
|
||||
with patch("mirage.core.google._client.aiohttp.ClientSession",
|
||||
return_value=_FakeSession()):
|
||||
config = GoogleConfig(
|
||||
client_id="id",
|
||||
client_secret="secret",
|
||||
refresh_token="rt",
|
||||
)
|
||||
await refresh_access_token(config)
|
||||
assert captured["data"]["client_secret"] == "secret"
|
||||
|
||||
|
||||
def test_google_config_inherited_by_docs():
|
||||
config = GDocsConfig(
|
||||
client_id="id",
|
||||
client_secret="secret",
|
||||
refresh_token="token",
|
||||
)
|
||||
assert isinstance(config, GoogleConfig)
|
||||
assert config.client_id == "id"
|
||||
|
||||
|
||||
def test_google_config_inherited_by_drive():
|
||||
config = GoogleDriveConfig(
|
||||
client_id="id",
|
||||
client_secret="secret",
|
||||
refresh_token="token",
|
||||
)
|
||||
assert isinstance(config, GoogleConfig)
|
||||
assert config.client_id == "id"
|
||||
@@ -0,0 +1,52 @@
|
||||
# ========= 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. =========
|
||||
|
||||
import pytest
|
||||
|
||||
from mirage.core.google.date_glob import glob_to_modified_range
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"pattern,expected",
|
||||
[
|
||||
("2026-*", ("2026-01-01T00:00:00Z", "2027-01-01T00:00:00Z")),
|
||||
("2026-05-*", ("2026-05-01T00:00:00Z", "2026-06-01T00:00:00Z")),
|
||||
("2026-12-*", ("2026-12-01T00:00:00Z", "2027-01-01T00:00:00Z")),
|
||||
("2026-05-03_*", ("2026-05-03T00:00:00Z", "2026-05-04T00:00:00Z")),
|
||||
("2026-12-31_*", ("2026-12-31T00:00:00Z", "2027-01-01T00:00:00Z")),
|
||||
],
|
||||
)
|
||||
def test_date_glob_translates(pattern, expected):
|
||||
assert glob_to_modified_range(pattern) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize(
|
||||
"pattern",
|
||||
[
|
||||
None,
|
||||
"",
|
||||
"*",
|
||||
"*.gdoc.json",
|
||||
"report-*",
|
||||
"2026",
|
||||
"20-*",
|
||||
"abc-2026-*",
|
||||
"2026-13-*",
|
||||
"2026-05-32_*",
|
||||
"2026-00-*",
|
||||
"2026-05-00_*",
|
||||
],
|
||||
)
|
||||
def test_date_glob_no_match_returns_none(pattern):
|
||||
assert glob_to_modified_range(pattern) is None
|
||||
@@ -0,0 +1,298 @@
|
||||
# ========= 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
|
||||
Reference in New Issue
Block a user