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,19 @@
|
||||
import inspect
|
||||
from types import SimpleNamespace
|
||||
|
||||
import aioresponses.core
|
||||
from aiohttp import ClientResponse
|
||||
|
||||
_NEEDS_STREAM_WRITER = "stream_writer" in inspect.signature(
|
||||
ClientResponse.__init__).parameters
|
||||
|
||||
|
||||
class _PatchedClientResponse(ClientResponse):
|
||||
|
||||
def __init__(self, *args: object, **kwargs: object) -> None:
|
||||
kwargs.setdefault("stream_writer", SimpleNamespace(output_size=0))
|
||||
super().__init__(*args, **kwargs)
|
||||
|
||||
|
||||
if _NEEDS_STREAM_WRITER:
|
||||
aioresponses.core.ClientResponse = _PatchedClientResponse
|
||||
@@ -0,0 +1,147 @@
|
||||
import pytest
|
||||
from aioresponses import aioresponses
|
||||
|
||||
from mirage.accessor.sharepoint import SharePointConfig
|
||||
from mirage.core.sharepoint._client import (GraphError, drive_ref_path,
|
||||
graph_get, graph_get_bytes,
|
||||
graph_list, headers, item_url)
|
||||
|
||||
|
||||
def _cfg(**kw) -> SharePointConfig:
|
||||
return SharePointConfig(access_token="tok", **kw)
|
||||
|
||||
|
||||
_BASE = "https://graph.microsoft.com/v1.0"
|
||||
_DRIVE = "b!drive123"
|
||||
|
||||
|
||||
def test_headers_carry_bearer_token():
|
||||
h = headers(_cfg())
|
||||
assert h["Authorization"] == "Bearer tok"
|
||||
|
||||
|
||||
def test_headers_resolves_callable_token():
|
||||
h = headers(SharePointConfig(access_token=lambda: "live"))
|
||||
assert h["Authorization"] == "Bearer live"
|
||||
|
||||
|
||||
def test_item_url_root_no_path():
|
||||
url = item_url(_DRIVE, "/")
|
||||
assert url == f"{_BASE}/drives/{_DRIVE}/root"
|
||||
|
||||
|
||||
def test_item_url_root_children():
|
||||
url = item_url(_DRIVE, "/", action="/children")
|
||||
assert url == f"{_BASE}/drives/{_DRIVE}/root/children"
|
||||
|
||||
|
||||
def test_item_url_nested_file():
|
||||
url = item_url(_DRIVE, "/docs/report.docx")
|
||||
assert url == f"{_BASE}/drives/{_DRIVE}/root:/docs/report.docx"
|
||||
|
||||
|
||||
def test_item_url_nested_content():
|
||||
url = item_url(_DRIVE, "/docs/report.docx", action="/content")
|
||||
assert url == f"{_BASE}/drives/{_DRIVE}/root:/docs/report.docx:/content"
|
||||
|
||||
|
||||
def test_item_url_nested_children():
|
||||
url = item_url(_DRIVE, "/folder", action="/children")
|
||||
assert url == f"{_BASE}/drives/{_DRIVE}/root:/folder:/children"
|
||||
|
||||
|
||||
def test_item_url_quotes_spaces():
|
||||
url = item_url(_DRIVE, "/My Folder/a b.txt")
|
||||
assert url == f"{_BASE}/drives/{_DRIVE}/root:/My%20Folder/a%20b.txt"
|
||||
|
||||
|
||||
def test_drive_ref_path_root():
|
||||
assert drive_ref_path(_DRIVE) == f"/drives/{_DRIVE}/root:"
|
||||
|
||||
|
||||
def test_drive_ref_path_folder():
|
||||
p = drive_ref_path(_DRIVE, "sub/dir")
|
||||
assert p == f"/drives/{_DRIVE}/root:/sub/dir"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_graph_get_returns_parsed_json():
|
||||
url = f"{_BASE}/drives/{_DRIVE}/root"
|
||||
with aioresponses() as m:
|
||||
m.get(url, payload={"id": "01ABC", "name": "root"})
|
||||
result = await graph_get(_cfg(), url)
|
||||
assert result["id"] == "01ABC"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_graph_get_raises_grapherror():
|
||||
url = f"{_BASE}/drives/{_DRIVE}/root"
|
||||
with aioresponses() as m:
|
||||
m.get(url,
|
||||
status=404,
|
||||
payload={"error": {
|
||||
"code": "itemNotFound",
|
||||
"message": "no"
|
||||
}})
|
||||
with pytest.raises(GraphError) as exc:
|
||||
await graph_get(_cfg(), url)
|
||||
assert exc.value.status == 404
|
||||
assert exc.value.code == "itemNotFound"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_graph_list_follows_nextlink():
|
||||
url = f"{_BASE}/drives/{_DRIVE}/root/children"
|
||||
page2 = url + "?$skiptoken=x"
|
||||
with aioresponses() as m:
|
||||
m.get(url, payload={"value": [{"id": "a"}], "@odata.nextLink": page2})
|
||||
m.get(page2, payload={"value": [{"id": "b"}]})
|
||||
items = await graph_list(_cfg(), url)
|
||||
assert [i["id"] for i in items] == ["a", "b"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_graph_get_bytes_returns_raw():
|
||||
url = f"{_BASE}/drives/{_DRIVE}/root:/a.txt:/content"
|
||||
with aioresponses() as m:
|
||||
m.get(url, body=b"hello")
|
||||
data = await graph_get_bytes(_cfg(), url)
|
||||
assert data == b"hello"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_retry_on_429():
|
||||
url = f"{_BASE}/drives/{_DRIVE}/root"
|
||||
with aioresponses() as m:
|
||||
m.get(url, status=429, headers={"Retry-After": "0"})
|
||||
m.get(url, payload={"id": "ok"})
|
||||
result = await graph_get(_cfg(), url)
|
||||
assert result["id"] == "ok"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_gives_up_after_max_retries():
|
||||
url = f"{_BASE}/drives/{_DRIVE}/root"
|
||||
with aioresponses() as m:
|
||||
for _ in range(3):
|
||||
m.get(url, status=429, headers={"Retry-After": "0"})
|
||||
with pytest.raises(GraphError) as exc:
|
||||
await graph_get(_cfg(max_retries=2), url)
|
||||
assert exc.value.status == 429
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_401_refreshes_callable_token():
|
||||
url = f"{_BASE}/drives/{_DRIVE}/root"
|
||||
calls = {"n": 0}
|
||||
|
||||
def provider():
|
||||
calls["n"] += 1
|
||||
return "fresh" if calls["n"] > 1 else "stale"
|
||||
|
||||
with aioresponses() as m:
|
||||
m.get(url, status=401, payload={"error": {"code": "x"}})
|
||||
m.get(url, payload={"id": "ok"})
|
||||
result = await graph_get(SharePointConfig(access_token=provider), url)
|
||||
assert result["id"] == "ok"
|
||||
assert calls["n"] == 2
|
||||
@@ -0,0 +1,67 @@
|
||||
import pytest
|
||||
from aioresponses import aioresponses
|
||||
|
||||
from mirage.accessor.sharepoint import SharePointAccessor, SharePointConfig
|
||||
from mirage.core.sharepoint._resolver import _drive_cache, _site_cache
|
||||
from mirage.core.sharepoint.du import du, du_all
|
||||
from mirage.types import PathSpec
|
||||
from mirage.utils.key_prefix import mount_key
|
||||
|
||||
_BASE = "https://graph.microsoft.com/v1.0"
|
||||
_SITE_ID = "tenant.sharepoint.com,site-guid,web-guid"
|
||||
_DRIVE_ID = "b!driveXYZ"
|
||||
|
||||
|
||||
def _accessor() -> SharePointAccessor:
|
||||
return SharePointAccessor(SharePointConfig(access_token="tok"))
|
||||
|
||||
|
||||
def _seed_caches():
|
||||
_site_cache["Engineering"] = _SITE_ID
|
||||
_drive_cache[(_SITE_ID, "Documents")] = _DRIVE_ID
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _reset_caches():
|
||||
_site_cache.clear()
|
||||
_drive_cache.clear()
|
||||
yield
|
||||
_site_cache.clear()
|
||||
_drive_cache.clear()
|
||||
|
||||
|
||||
def _file_path() -> PathSpec:
|
||||
return PathSpec(resource_path=mount_key("/sp/Engineering/Documents/a.txt",
|
||||
"/sp"),
|
||||
virtual="/sp/Engineering/Documents/a.txt",
|
||||
directory="/sp/Engineering/Documents")
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_du_of_file_returns_its_own_size():
|
||||
_seed_caches()
|
||||
with aioresponses() as m:
|
||||
m.get(f"{_BASE}/drives/{_DRIVE_ID}/root:/a.txt",
|
||||
payload={
|
||||
"id": "1",
|
||||
"name": "a.txt",
|
||||
"size": 3,
|
||||
"file": {}
|
||||
})
|
||||
total = await du(_accessor(), _file_path())
|
||||
assert total == 3
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_du_all_of_file_is_empty():
|
||||
_seed_caches()
|
||||
with aioresponses() as m:
|
||||
m.get(f"{_BASE}/drives/{_DRIVE_ID}/root:/a.txt",
|
||||
payload={
|
||||
"id": "1",
|
||||
"name": "a.txt",
|
||||
"size": 3,
|
||||
"file": {}
|
||||
})
|
||||
rows = await du_all(_accessor(), _file_path())
|
||||
assert rows == []
|
||||
@@ -0,0 +1,84 @@
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
|
||||
from mirage.core.sharepoint import find as find_mod
|
||||
from mirage.core.sharepoint._resolver import ResolvedPath
|
||||
from mirage.types import PathSpec
|
||||
from mirage.utils.key_prefix import mount_key
|
||||
|
||||
_TREE = [
|
||||
("reports/a.txt", {
|
||||
"name": "a.txt",
|
||||
"size": 10
|
||||
}, False),
|
||||
("reports/sub", {
|
||||
"name": "sub",
|
||||
"folder": {}
|
||||
}, True),
|
||||
("reports/sub/b.txt", {
|
||||
"name": "b.txt",
|
||||
"size": 20
|
||||
}, False),
|
||||
]
|
||||
|
||||
|
||||
class _FakeSession:
|
||||
|
||||
async def __aenter__(self):
|
||||
return self
|
||||
|
||||
async def __aexit__(self, *exc):
|
||||
return False
|
||||
|
||||
|
||||
async def _fake_iter_tree(config, drive_id, base, session=None):
|
||||
for rel, item, is_dir in _TREE:
|
||||
yield rel, item, is_dir
|
||||
|
||||
|
||||
async def _fake_resolve(accessor, path):
|
||||
return ResolvedPath(level="item", drive_id="d", item_path="reports")
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def _patched(monkeypatch):
|
||||
monkeypatch.setattr(find_mod, "resolve", _fake_resolve)
|
||||
monkeypatch.setattr(find_mod, "iter_tree", _fake_iter_tree)
|
||||
monkeypatch.setattr(find_mod, "new_session", lambda config: _FakeSession())
|
||||
|
||||
|
||||
def _spec() -> PathSpec:
|
||||
return PathSpec(resource_path=mount_key("/sp/reports", "/sp"),
|
||||
virtual="/sp/reports",
|
||||
directory="/sp/reports")
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_find_emits_mount_root(_patched):
|
||||
acc = SimpleNamespace(config=None)
|
||||
out = await find_mod.find(acc, _spec())
|
||||
assert out == [
|
||||
"/reports", "/reports/a.txt", "/reports/sub", "/reports/sub/b.txt"
|
||||
]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_find_name_matches_mount_root_start_path(_patched):
|
||||
acc = SimpleNamespace(config=None)
|
||||
out = await find_mod.find(acc, _spec(), name="reports")
|
||||
assert out == ["/reports"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_find_type_dir_includes_root(_patched):
|
||||
acc = SimpleNamespace(config=None)
|
||||
out = await find_mod.find(acc, _spec(), type="d")
|
||||
assert out == ["/reports", "/reports/sub"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_find_maxdepth_one(_patched):
|
||||
acc = SimpleNamespace(config=None)
|
||||
out = await find_mod.find(acc, _spec(), maxdepth=1)
|
||||
assert out == ["/reports", "/reports/a.txt", "/reports/sub"]
|
||||
@@ -0,0 +1,85 @@
|
||||
import pytest
|
||||
from aioresponses import CallbackResult, aioresponses
|
||||
|
||||
from mirage.accessor.sharepoint import SharePointAccessor, SharePointConfig
|
||||
from mirage.core.sharepoint._resolver import _drive_cache, _site_cache
|
||||
from mirage.core.sharepoint.read import read_bytes
|
||||
from mirage.types import PathSpec
|
||||
from mirage.utils.key_prefix import mount_key
|
||||
|
||||
_BASE = "https://graph.microsoft.com/v1.0"
|
||||
_SITE_ID = "tenant.sharepoint.com,site-guid,web-guid"
|
||||
_DRIVE_ID = "b!driveXYZ"
|
||||
|
||||
|
||||
def _accessor() -> SharePointAccessor:
|
||||
return SharePointAccessor(SharePointConfig(access_token="tok"))
|
||||
|
||||
|
||||
def _seed_caches():
|
||||
_site_cache["Engineering"] = _SITE_ID
|
||||
_drive_cache[(_SITE_ID, "Documents")] = _DRIVE_ID
|
||||
|
||||
|
||||
def _clear_caches():
|
||||
_site_cache.clear()
|
||||
_drive_cache.clear()
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _reset_caches():
|
||||
_clear_caches()
|
||||
_seed_caches()
|
||||
yield
|
||||
_clear_caches()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_read_returns_content():
|
||||
url = f"{_BASE}/drives/{_DRIVE_ID}/root:/report.txt:/content"
|
||||
with aioresponses() as m:
|
||||
m.get(url, body=b"file content")
|
||||
path = PathSpec(resource_path=mount_key(
|
||||
"/sp/Engineering/Documents/report.txt", "/sp"),
|
||||
virtual="/sp/Engineering/Documents/report.txt",
|
||||
directory="/sp/Engineering/Documents/report.txt")
|
||||
data = await read_bytes(_accessor(), path)
|
||||
assert data == b"file content"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_read_missing_raises_file_not_found():
|
||||
url = f"{_BASE}/drives/{_DRIVE_ID}/root:/nope.txt:/content"
|
||||
with aioresponses() as m:
|
||||
m.get(url,
|
||||
status=404,
|
||||
payload={"error": {
|
||||
"code": "itemNotFound",
|
||||
"message": "no"
|
||||
}})
|
||||
path = PathSpec(resource_path=mount_key(
|
||||
"/sp/Engineering/Documents/nope.txt", "/sp"),
|
||||
virtual="/sp/Engineering/Documents/nope.txt",
|
||||
directory="/sp/Engineering/Documents/nope.txt")
|
||||
with pytest.raises(FileNotFoundError):
|
||||
await read_bytes(_accessor(), path)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_read_range():
|
||||
url = f"{_BASE}/drives/{_DRIVE_ID}/root:/data.bin:/content"
|
||||
captured = {}
|
||||
|
||||
def _cb(url, **kwargs):
|
||||
captured["range"] = kwargs["headers"].get("Range")
|
||||
return CallbackResult(body=b"llo")
|
||||
|
||||
with aioresponses() as m:
|
||||
m.get(url, callback=_cb)
|
||||
path = PathSpec(resource_path=mount_key(
|
||||
"/sp/Engineering/Documents/data.bin", "/sp"),
|
||||
virtual="/sp/Engineering/Documents/data.bin",
|
||||
directory="/sp/Engineering/Documents/data.bin")
|
||||
data = await read_bytes(_accessor(), path, offset=2, size=3)
|
||||
assert captured["range"] == "bytes=2-4"
|
||||
assert data == b"llo"
|
||||
@@ -0,0 +1,231 @@
|
||||
import re
|
||||
|
||||
import pytest
|
||||
from aioresponses import aioresponses
|
||||
|
||||
from mirage.accessor.sharepoint import SharePointAccessor, SharePointConfig
|
||||
from mirage.cache.index import RAMIndexCacheStore
|
||||
from mirage.core.sharepoint._resolver import _drive_cache, _site_cache
|
||||
from mirage.core.sharepoint.readdir import readdir
|
||||
from mirage.types import PathSpec
|
||||
from mirage.utils.key_prefix import mount_key
|
||||
|
||||
_BASE = "https://graph.microsoft.com/v1.0"
|
||||
_SITE_ID = "tenant.sharepoint.com,site-guid,web-guid"
|
||||
_DRIVE_ID = "b!driveXYZ"
|
||||
|
||||
_SITES_RE = re.compile(r".*/sites\??.*")
|
||||
_DRIVES_RE = re.compile(r".*/sites/.*/drives\??.*")
|
||||
|
||||
|
||||
def _accessor() -> SharePointAccessor:
|
||||
return SharePointAccessor(SharePointConfig(access_token="tok"))
|
||||
|
||||
|
||||
def _seed_caches():
|
||||
_site_cache["Engineering"] = _SITE_ID
|
||||
_drive_cache[(_SITE_ID, "Documents")] = _DRIVE_ID
|
||||
|
||||
|
||||
def _clear_caches():
|
||||
_site_cache.clear()
|
||||
_drive_cache.clear()
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _reset_caches():
|
||||
_clear_caches()
|
||||
yield
|
||||
_clear_caches()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_readdir_root_lists_sites():
|
||||
index = RAMIndexCacheStore()
|
||||
with aioresponses() as m:
|
||||
m.get(_SITES_RE,
|
||||
payload={
|
||||
"value": [
|
||||
{
|
||||
"id": "s1",
|
||||
"displayName": "Engineering",
|
||||
"name": "eng"
|
||||
},
|
||||
{
|
||||
"id": "s2",
|
||||
"displayName": "Marketing",
|
||||
"name": "mkt"
|
||||
},
|
||||
]
|
||||
})
|
||||
path = PathSpec(resource_path=mount_key("/sp/", "/sp"),
|
||||
virtual="/sp/",
|
||||
directory="/sp/")
|
||||
names = await readdir(_accessor(), path, index)
|
||||
assert "/sp/Engineering" in names
|
||||
assert "/sp/Marketing" in names
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_readdir_site_lists_drives():
|
||||
_site_cache["Engineering"] = _SITE_ID
|
||||
index = RAMIndexCacheStore()
|
||||
with aioresponses() as m:
|
||||
m.get(_DRIVES_RE,
|
||||
payload={
|
||||
"value": [
|
||||
{
|
||||
"id": _DRIVE_ID,
|
||||
"name": "Documents"
|
||||
},
|
||||
{
|
||||
"id": "b!other",
|
||||
"name": "Archives"
|
||||
},
|
||||
]
|
||||
})
|
||||
path = PathSpec(resource_path=mount_key("/sp/Engineering", "/sp"),
|
||||
virtual="/sp/Engineering",
|
||||
directory="/sp/Engineering")
|
||||
names = await readdir(_accessor(), path, index)
|
||||
assert "/sp/Engineering/Archives" in names
|
||||
assert "/sp/Engineering/Documents" in names
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_readdir_drive_root_lists_children():
|
||||
_seed_caches()
|
||||
index = RAMIndexCacheStore()
|
||||
with aioresponses() as m:
|
||||
m.get(f"{_BASE}/drives/{_DRIVE_ID}/root/children",
|
||||
payload={
|
||||
"value": [
|
||||
{
|
||||
"id": "1",
|
||||
"name": "readme.md",
|
||||
"size": 100,
|
||||
"file": {},
|
||||
"lastModifiedDateTime": "2026-06-01T10:00:00Z"
|
||||
},
|
||||
{
|
||||
"id": "2",
|
||||
"name": "src",
|
||||
"size": 0,
|
||||
"folder": {
|
||||
"childCount": 5
|
||||
},
|
||||
"lastModifiedDateTime": "2026-06-02T10:00:00Z"
|
||||
},
|
||||
]
|
||||
})
|
||||
path = PathSpec(resource_path=mount_key("/sp/Engineering/Documents",
|
||||
"/sp"),
|
||||
virtual="/sp/Engineering/Documents",
|
||||
directory="/sp/Engineering/Documents")
|
||||
names = await readdir(_accessor(), path, index)
|
||||
assert "/sp/Engineering/Documents/readme.md" in names
|
||||
assert "/sp/Engineering/Documents/src" in names
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_readdir_populates_index_with_metadata():
|
||||
_seed_caches()
|
||||
index = RAMIndexCacheStore()
|
||||
with aioresponses() as m:
|
||||
m.get(f"{_BASE}/drives/{_DRIVE_ID}/root/children",
|
||||
payload={
|
||||
"value": [
|
||||
{
|
||||
"id": "1",
|
||||
"name": "a.txt",
|
||||
"size": 42,
|
||||
"file": {},
|
||||
"lastModifiedDateTime": "2026-06-15T08:00:00Z"
|
||||
},
|
||||
]
|
||||
})
|
||||
path = PathSpec(resource_path=mount_key("/sp/Engineering/Documents",
|
||||
"/sp"),
|
||||
virtual="/sp/Engineering/Documents",
|
||||
directory="/sp/Engineering/Documents")
|
||||
await readdir(_accessor(), path, index)
|
||||
lookup = await index.get("/sp/Engineering/Documents/a.txt")
|
||||
assert lookup.entry is not None
|
||||
assert lookup.entry.size == 42
|
||||
assert lookup.entry.remote_time == "2026-06-15T08:00:00Z"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_readdir_subfolder():
|
||||
_seed_caches()
|
||||
index = RAMIndexCacheStore()
|
||||
with aioresponses() as m:
|
||||
m.get(f"{_BASE}/drives/{_DRIVE_ID}/root:/src:/children",
|
||||
payload={
|
||||
"value": [
|
||||
{
|
||||
"id": "3",
|
||||
"name": "main.py",
|
||||
"size": 200,
|
||||
"file": {}
|
||||
},
|
||||
]
|
||||
})
|
||||
path = PathSpec(resource_path=mount_key(
|
||||
"/sp/Engineering/Documents/src", "/sp"),
|
||||
virtual="/sp/Engineering/Documents/src",
|
||||
directory="/sp/Engineering/Documents/src")
|
||||
names = await readdir(_accessor(), path, index)
|
||||
assert "/sp/Engineering/Documents/src/main.py" in names
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_readdir_of_file_raises_not_a_directory():
|
||||
_seed_caches()
|
||||
index = RAMIndexCacheStore()
|
||||
with aioresponses() as m:
|
||||
m.get(f"{_BASE}/drives/{_DRIVE_ID}/root:/a.txt:/children",
|
||||
status=404,
|
||||
payload={"error": {
|
||||
"code": "itemNotFound",
|
||||
"message": "x"
|
||||
}})
|
||||
m.get(f"{_BASE}/drives/{_DRIVE_ID}/root:/a.txt",
|
||||
payload={
|
||||
"id": "1",
|
||||
"name": "a.txt",
|
||||
"size": 3,
|
||||
"file": {}
|
||||
})
|
||||
path = PathSpec(resource_path=mount_key(
|
||||
"/sp/Engineering/Documents/a.txt", "/sp"),
|
||||
virtual="/sp/Engineering/Documents/a.txt",
|
||||
directory="/sp/Engineering/Documents")
|
||||
with pytest.raises(NotADirectoryError):
|
||||
await readdir(_accessor(), path, index)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_readdir_cache_hit():
|
||||
_seed_caches()
|
||||
index = RAMIndexCacheStore()
|
||||
with aioresponses() as m:
|
||||
m.get(f"{_BASE}/drives/{_DRIVE_ID}/root/children",
|
||||
payload={
|
||||
"value": [
|
||||
{
|
||||
"id": "1",
|
||||
"name": "cached.txt",
|
||||
"size": 10,
|
||||
"file": {}
|
||||
},
|
||||
]
|
||||
})
|
||||
path = PathSpec(resource_path=mount_key("/sp/Engineering/Documents",
|
||||
"/sp"),
|
||||
virtual="/sp/Engineering/Documents",
|
||||
directory="/sp/Engineering/Documents")
|
||||
await readdir(_accessor(), path, index)
|
||||
# Second call should hit cache, no extra HTTP call
|
||||
names = await readdir(_accessor(), path, index)
|
||||
assert "/sp/Engineering/Documents/cached.txt" in names
|
||||
@@ -0,0 +1,97 @@
|
||||
import re
|
||||
|
||||
import pytest
|
||||
from aioresponses import aioresponses
|
||||
|
||||
from mirage.accessor.sharepoint import SharePointAccessor, SharePointConfig
|
||||
from mirage.core.sharepoint._resolver import _drive_cache, _site_cache, resolve
|
||||
from mirage.types import PathSpec
|
||||
from mirage.utils.key_prefix import mount_key
|
||||
|
||||
_SITE_ID = "tenant.sharepoint.com,site-guid,web-guid"
|
||||
_DRIVE_ID = "b!driveXYZ"
|
||||
_SITES_RE = re.compile(r".*/sites\??.*")
|
||||
|
||||
|
||||
def _accessor() -> SharePointAccessor:
|
||||
return SharePointAccessor(SharePointConfig(access_token="tok"))
|
||||
|
||||
|
||||
def _clear_caches():
|
||||
_site_cache.clear()
|
||||
_drive_cache.clear()
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _reset_caches():
|
||||
_clear_caches()
|
||||
yield
|
||||
_clear_caches()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_resolve_root():
|
||||
path = PathSpec(resource_path=mount_key("/sp/", "/sp"),
|
||||
virtual="/sp/",
|
||||
directory="/sp/")
|
||||
result = await resolve(_accessor(), path)
|
||||
assert result.level == "root"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_resolve_site():
|
||||
_site_cache["Engineering"] = _SITE_ID
|
||||
path = PathSpec(resource_path=mount_key("/sp/Engineering", "/sp"),
|
||||
virtual="/sp/Engineering",
|
||||
directory="/sp/Engineering")
|
||||
result = await resolve(_accessor(), path)
|
||||
assert result.level == "site"
|
||||
assert result.site_id == _SITE_ID
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_resolve_drive():
|
||||
_site_cache["Engineering"] = _SITE_ID
|
||||
_drive_cache[(_SITE_ID, "Documents")] = _DRIVE_ID
|
||||
path = PathSpec(resource_path=mount_key("/sp/Engineering/Documents",
|
||||
"/sp"),
|
||||
virtual="/sp/Engineering/Documents",
|
||||
directory="/sp/Engineering/Documents")
|
||||
result = await resolve(_accessor(), path)
|
||||
assert result.level == "drive"
|
||||
assert result.drive_id == _DRIVE_ID
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_resolve_item():
|
||||
_site_cache["Engineering"] = _SITE_ID
|
||||
_drive_cache[(_SITE_ID, "Documents")] = _DRIVE_ID
|
||||
path = PathSpec(resource_path=mount_key(
|
||||
"/sp/Engineering/Documents/sub/file.txt", "/sp"),
|
||||
virtual="/sp/Engineering/Documents/sub/file.txt",
|
||||
directory="/sp/Engineering/Documents/sub/file.txt")
|
||||
result = await resolve(_accessor(), path)
|
||||
assert result.level == "item"
|
||||
assert result.drive_id == _DRIVE_ID
|
||||
assert result.item_path == "sub/file.txt"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_resolve_unknown_site():
|
||||
with aioresponses() as m:
|
||||
m.get(_SITES_RE,
|
||||
payload={
|
||||
"value": [
|
||||
{
|
||||
"id": "other-id",
|
||||
"displayName": "Other",
|
||||
"name": "other"
|
||||
},
|
||||
]
|
||||
})
|
||||
path = PathSpec(resource_path=mount_key("/sp/NoSuchSite", "/sp"),
|
||||
virtual="/sp/NoSuchSite",
|
||||
directory="/sp/NoSuchSite")
|
||||
result = await resolve(_accessor(), path)
|
||||
assert result.level == "site"
|
||||
assert result.site_id is None
|
||||
@@ -0,0 +1,198 @@
|
||||
import pytest
|
||||
from aioresponses import aioresponses
|
||||
|
||||
from mirage.accessor.sharepoint import SharePointAccessor, SharePointConfig
|
||||
from mirage.cache.index import RAMIndexCacheStore
|
||||
from mirage.core.sharepoint._resolver import _drive_cache, _site_cache
|
||||
from mirage.core.sharepoint.readdir import readdir
|
||||
from mirage.core.sharepoint.stat import stat
|
||||
from mirage.types import FileType, PathSpec
|
||||
from mirage.utils.key_prefix import mount_key
|
||||
|
||||
_BASE = "https://graph.microsoft.com/v1.0"
|
||||
_SITE_ID = "tenant.sharepoint.com,site-guid,web-guid"
|
||||
_DRIVE_ID = "b!driveXYZ"
|
||||
|
||||
|
||||
def _accessor() -> SharePointAccessor:
|
||||
return SharePointAccessor(SharePointConfig(access_token="tok"))
|
||||
|
||||
|
||||
def _seed_caches():
|
||||
_site_cache["Engineering"] = _SITE_ID
|
||||
_drive_cache[(_SITE_ID, "Documents")] = _DRIVE_ID
|
||||
|
||||
|
||||
def _clear_caches():
|
||||
_site_cache.clear()
|
||||
_drive_cache.clear()
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _reset_caches():
|
||||
_clear_caches()
|
||||
yield
|
||||
_clear_caches()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_stat_root_is_directory():
|
||||
path = PathSpec(resource_path=mount_key("/sp/", "/sp"),
|
||||
virtual="/sp/",
|
||||
directory="/sp/")
|
||||
result = await stat(_accessor(), path)
|
||||
assert result.type == FileType.DIRECTORY
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_stat_site_is_directory():
|
||||
_site_cache["Engineering"] = _SITE_ID
|
||||
with aioresponses() as m:
|
||||
m.get(f"{_BASE}/sites",
|
||||
payload={
|
||||
"value": [
|
||||
{
|
||||
"id": _SITE_ID,
|
||||
"displayName": "Engineering",
|
||||
"name": "eng"
|
||||
},
|
||||
]
|
||||
})
|
||||
path = PathSpec(resource_path=mount_key("/sp/Engineering", "/sp"),
|
||||
virtual="/sp/Engineering",
|
||||
directory="/sp/Engineering")
|
||||
result = await stat(_accessor(), path)
|
||||
assert result.type == FileType.DIRECTORY
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_stat_drive_is_directory():
|
||||
_seed_caches()
|
||||
path = PathSpec(resource_path=mount_key("/sp/Engineering/Documents",
|
||||
"/sp"),
|
||||
virtual="/sp/Engineering/Documents",
|
||||
directory="/sp/Engineering/Documents")
|
||||
result = await stat(_accessor(), path)
|
||||
assert result.type == FileType.DIRECTORY
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_stat_file_from_api():
|
||||
_seed_caches()
|
||||
url = f"{_BASE}/drives/{_DRIVE_ID}/root:/report.docx"
|
||||
with aioresponses() as m:
|
||||
m.get(url,
|
||||
payload={
|
||||
"id": "01ITEM",
|
||||
"name": "report.docx",
|
||||
"size": 1234,
|
||||
"lastModifiedDateTime": "2026-05-01T10:00:00Z",
|
||||
"cTag": "ctag-abc",
|
||||
"eTag": "etag-xyz",
|
||||
"file": {
|
||||
"mimeType": "application/vnd.openxml"
|
||||
},
|
||||
})
|
||||
path = PathSpec(resource_path=mount_key(
|
||||
"/sp/Engineering/Documents/report.docx", "/sp"),
|
||||
virtual="/sp/Engineering/Documents/report.docx",
|
||||
directory="/sp/Engineering/Documents/report.docx")
|
||||
result = await stat(_accessor(), path)
|
||||
assert result.name == "report.docx"
|
||||
assert result.size == 1234
|
||||
assert result.modified == "2026-05-01T10:00:00Z"
|
||||
assert result.fingerprint == "ctag-abc"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_stat_folder_from_api():
|
||||
_seed_caches()
|
||||
url = f"{_BASE}/drives/{_DRIVE_ID}/root:/src"
|
||||
with aioresponses() as m:
|
||||
m.get(url,
|
||||
payload={
|
||||
"id": "02FOLDER",
|
||||
"name": "src",
|
||||
"size": 4096,
|
||||
"lastModifiedDateTime": "2026-05-01T10:00:00Z",
|
||||
"folder": {
|
||||
"childCount": 2
|
||||
},
|
||||
})
|
||||
path = PathSpec(resource_path=mount_key(
|
||||
"/sp/Engineering/Documents/src", "/sp"),
|
||||
virtual="/sp/Engineering/Documents/src",
|
||||
directory="/sp/Engineering/Documents/src")
|
||||
result = await stat(_accessor(), path)
|
||||
assert result.type == FileType.DIRECTORY
|
||||
assert result.name == "src"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_stat_missing_raises_file_not_found():
|
||||
_seed_caches()
|
||||
url = f"{_BASE}/drives/{_DRIVE_ID}/root:/nope.txt"
|
||||
with aioresponses() as m:
|
||||
m.get(url,
|
||||
status=404,
|
||||
payload={"error": {
|
||||
"code": "itemNotFound",
|
||||
"message": "no"
|
||||
}})
|
||||
path = PathSpec(resource_path=mount_key(
|
||||
"/sp/Engineering/Documents/nope.txt", "/sp"),
|
||||
virtual="/sp/Engineering/Documents/nope.txt",
|
||||
directory="/sp/Engineering/Documents/nope.txt")
|
||||
with pytest.raises(FileNotFoundError):
|
||||
await stat(_accessor(), path)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_stat_from_index_after_readdir():
|
||||
_seed_caches()
|
||||
index = RAMIndexCacheStore()
|
||||
with aioresponses() as m:
|
||||
m.get(f"{_BASE}/drives/{_DRIVE_ID}/root/children",
|
||||
payload={
|
||||
"value": [
|
||||
{
|
||||
"id": "1",
|
||||
"name": "notes.txt",
|
||||
"size": 42,
|
||||
"file": {},
|
||||
"lastModifiedDateTime": "2026-06-19T09:28:00Z"
|
||||
},
|
||||
]
|
||||
})
|
||||
parent = PathSpec(resource_path=mount_key("/sp/Engineering/Documents",
|
||||
"/sp"),
|
||||
virtual="/sp/Engineering/Documents",
|
||||
directory="/sp/Engineering/Documents")
|
||||
await readdir(_accessor(), parent, index)
|
||||
path = PathSpec(resource_path=mount_key(
|
||||
"/sp/Engineering/Documents/notes.txt", "/sp"),
|
||||
virtual="/sp/Engineering/Documents/notes.txt",
|
||||
directory="/sp/Engineering/Documents/notes.txt")
|
||||
result = await stat(_accessor(), path, index)
|
||||
assert result.name == "notes.txt"
|
||||
assert result.size == 42
|
||||
assert result.modified == "2026-06-19T09:28:00Z"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_stat_site_and_drive_have_no_metadata():
|
||||
_seed_caches()
|
||||
site_path = PathSpec(resource_path=mount_key("/sp/Engineering", "/sp"),
|
||||
virtual="/sp/Engineering",
|
||||
directory="/sp/Engineering")
|
||||
result = await stat(_accessor(), site_path)
|
||||
assert result.size is None
|
||||
assert result.modified is None
|
||||
|
||||
drive_path = PathSpec(resource_path=mount_key("/sp/Engineering/Documents",
|
||||
"/sp"),
|
||||
virtual="/sp/Engineering/Documents",
|
||||
directory="/sp/Engineering/Documents")
|
||||
result = await stat(_accessor(), drive_path)
|
||||
assert result.size is None
|
||||
assert result.modified is None
|
||||
@@ -0,0 +1,83 @@
|
||||
import pytest
|
||||
from aioresponses import CallbackResult, aioresponses
|
||||
|
||||
import mirage.core.sharepoint.write as write_mod
|
||||
from mirage.accessor.sharepoint import SharePointAccessor, SharePointConfig
|
||||
from mirage.core.sharepoint._resolver import _drive_cache, _site_cache
|
||||
from mirage.core.sharepoint.write import write_bytes
|
||||
from mirage.types import PathSpec
|
||||
from mirage.utils.key_prefix import mount_key
|
||||
|
||||
_BASE = "https://graph.microsoft.com/v1.0"
|
||||
_SITE_ID = "tenant.sharepoint.com,site-guid,web-guid"
|
||||
_DRIVE_ID = "b!driveXYZ"
|
||||
|
||||
|
||||
def _accessor() -> SharePointAccessor:
|
||||
return SharePointAccessor(SharePointConfig(access_token="tok"))
|
||||
|
||||
|
||||
def _seed_caches():
|
||||
_site_cache["Engineering"] = _SITE_ID
|
||||
_drive_cache[(_SITE_ID, "Documents")] = _DRIVE_ID
|
||||
|
||||
|
||||
def _clear_caches():
|
||||
_site_cache.clear()
|
||||
_drive_cache.clear()
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def _reset_caches():
|
||||
_clear_caches()
|
||||
_seed_caches()
|
||||
yield
|
||||
_clear_caches()
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_write_small_file():
|
||||
url = f"{_BASE}/drives/{_DRIVE_ID}/root:/a.txt:/content"
|
||||
captured = {}
|
||||
|
||||
def _cb(url, **kwargs):
|
||||
captured["body"] = kwargs.get("data")
|
||||
return CallbackResult(status=201, payload={"id": "X", "name": "a.txt"})
|
||||
|
||||
with aioresponses() as m:
|
||||
m.put(url, callback=_cb)
|
||||
path = PathSpec(resource_path=mount_key(
|
||||
"/sp/Engineering/Documents/a.txt", "/sp"),
|
||||
virtual="/sp/Engineering/Documents/a.txt",
|
||||
directory="/sp/Engineering/Documents/a.txt")
|
||||
await write_bytes(_accessor(), path, b"hello")
|
||||
assert captured["body"] == b"hello"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_write_large_file_uses_upload_session(monkeypatch):
|
||||
monkeypatch.setattr(write_mod, "SIMPLE_UPLOAD_MAX", 4)
|
||||
monkeypatch.setattr(write_mod, "UPLOAD_CHUNK", 4)
|
||||
ranges = []
|
||||
|
||||
def _chunk_cb(url, **kwargs):
|
||||
ranges.append(kwargs["headers"]["Content-Range"])
|
||||
return CallbackResult(status=202, payload={})
|
||||
|
||||
def _final_cb(url, **kwargs):
|
||||
ranges.append(kwargs["headers"]["Content-Range"])
|
||||
return CallbackResult(status=201, payload={"id": "X"})
|
||||
|
||||
session_url = (f"{_BASE}/drives/{_DRIVE_ID}"
|
||||
"/root:/big.bin:/createUploadSession")
|
||||
upload_url = "https://upload.example/session1"
|
||||
with aioresponses() as m:
|
||||
m.post(session_url, payload={"uploadUrl": upload_url})
|
||||
m.put(upload_url, callback=_chunk_cb)
|
||||
m.put(upload_url, callback=_final_cb)
|
||||
path = PathSpec(resource_path=mount_key(
|
||||
"/sp/Engineering/Documents/big.bin", "/sp"),
|
||||
virtual="/sp/Engineering/Documents/big.bin",
|
||||
directory="/sp/Engineering/Documents/big.bin")
|
||||
await write_bytes(_accessor(), path, b"abcdef")
|
||||
assert ranges == ["bytes 0-3/6", "bytes 4-5/6"]
|
||||
Reference in New Issue
Block a user