Close the remaining places where an extension point was hardcoded, and expose a stable public import surface for every app. - files: register_storage_backend(...) / STORAGE_BACKENDS[name]["CLASS"]; unknown backends now fail loudly instead of silently using local - files: PipelineStepRegistry + @pipeline_step; PIPELINE_EXECUTOR setting - billing: INVOICE_PDF_BUILDER setting - security: TWO_FACTOR_SERVICE / TWO_FACTOR_RECOVERY_SERVICE settings - all app packages expose lazy public exports (PEP 562); infrasynth.shared re-exports its primitives eagerly - README documents the per-module extension-point table - tests/test_extensibility.py pins each hook plus the public surface
63 lines
2 KiB
Python
63 lines
2 KiB
Python
import io
|
|
|
|
import pytest
|
|
|
|
from infrasynth.files.storage import _LocalStorage, get_storage_backend
|
|
|
|
pytestmark = pytest.mark.django_db
|
|
|
|
|
|
class TestLocalStorage:
|
|
def test_save_and_open_roundtrip(self, media_root):
|
|
storage = _LocalStorage({})
|
|
name = storage.save("dir/file.txt", io.BytesIO(b"hello"))
|
|
assert name.endswith("file.txt")
|
|
assert storage.open(name, "rb").read() == b"hello"
|
|
|
|
def test_exists(self, media_root):
|
|
storage = _LocalStorage({})
|
|
name = storage.save("a.txt", io.BytesIO(b"data"))
|
|
assert storage.exists(name)
|
|
assert not storage.exists("nope.txt")
|
|
|
|
def test_delete(self, media_root):
|
|
storage = _LocalStorage({})
|
|
name = storage.save("b.txt", io.BytesIO(b"data"))
|
|
storage.delete(name)
|
|
assert not storage.exists(name)
|
|
|
|
def test_url(self, media_root):
|
|
storage = _LocalStorage({})
|
|
name = storage.save("c.txt", io.BytesIO(b"data"))
|
|
url = storage.url(name)
|
|
assert "media" in url
|
|
assert url.endswith("c.txt")
|
|
|
|
def test_signed_url_equals_url_for_local(self, media_root):
|
|
storage = _LocalStorage({})
|
|
name = storage.save("d.txt", io.BytesIO(b"data"))
|
|
assert storage.generate_signed_url(name, 60) == storage.url(name)
|
|
|
|
|
|
class TestGetStorageBackend:
|
|
def test_default_is_local(self):
|
|
storage = get_storage_backend()
|
|
assert isinstance(storage, _LocalStorage)
|
|
|
|
def test_unknown_backend_raises(self):
|
|
from django.core.exceptions import ImproperlyConfigured
|
|
|
|
with pytest.raises(ImproperlyConfigured):
|
|
get_storage_backend("nonexistent")
|
|
|
|
def test_local_backend_instantiation(self):
|
|
assert isinstance(get_storage_backend("local"), _LocalStorage)
|
|
|
|
|
|
class TestSaveFile:
|
|
def test_save_file_returns_key(self, media_root):
|
|
from infrasynth.files.storage import save_file
|
|
|
|
key = save_file(io.BytesIO(b"content"), "uploads/x.txt", backend="local")
|
|
assert key.endswith("x.txt")
|
|
assert (media_root / key).exists()
|