You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

56 lines
1.9 KiB

from datetime import datetime
from app.core.storage_layout import build_blob_storage_key
from app.core.storage_layout import build_export_snapshot_storage_key
from app.core.storage_layout import build_manifest_storage_key
from app.core.storage_layout import build_preview_artifact_storage_key
from app.models.entities import Blob
def test_build_blob_storage_key_uses_structured_object_layout() -> None:
blob = Blob(
id="blb_test",
file_version_id="ver_test",
blob_index=0,
kind="file",
content_hash="7335cc7645d24642dd0ff7873f55163d39853da4a747f8c630b950e51018423e",
size_bytes=11,
logical_offset=0,
)
assert build_blob_storage_key(blob) == (
"objects/file/sha256/73/35/"
"7335cc7645d24642dd0ff7873f55163d39853da4a747f8c630b950e51018423e.blob"
)
def test_build_preview_artifact_storage_key_uses_preview_namespace() -> None:
blob = Blob(
id="blb_preview",
file_version_id="ver_preview",
blob_index=0,
kind="file",
content_hash="aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
size_bytes=128,
logical_offset=0,
)
assert build_preview_artifact_storage_key(artifact_type="inline_preview", blob=blob) == (
"objects/preview/inline_preview/sha256/aa/aa/"
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa.blob"
)
def test_build_export_snapshot_storage_key_uses_date_partitions() -> None:
exported_at = datetime(2026, 4, 17, 15, 30, 45)
assert build_export_snapshot_storage_key(
exported_at=exported_at,
digest="Snapshot:Primary",
) == "objects/export/metadata/2026/04/17/snapshot-primary.json"
def test_build_manifest_storage_key_normalizes_scope_and_identifier() -> None:
assert build_manifest_storage_key(
scope="placement policy",
identifier="Other/Primary",
) == "objects/manifest/placement-policy/other-primary.json"