Spaces:
Runtime error
Runtime error
Download backend/tests/storage/test_factory.py from Talosware/talos-access: direct link, hf CLI and curl.
- Browser
- Download file 1.55 kB
-
https://huggingface.co/spaces/Talosware/talos-access/resolve/main/backend/tests/storage/test_factory.py
- Command line
-
hf download hf://spaces/Talosware/talos-access/backend/tests/storage/test_factory.py
-
curl -L -o test_factory.py https://huggingface.co/spaces/Talosware/talos-access/resolve/main/backend/tests/storage/test_factory.py
1.55 kB
| import pytest | |
| from app.storage import get_storage | |
| from app.storage.local_disk import LocalDiskStorage | |
| from app.storage.supabase import SupabaseStorage | |
| def test_default_backend_is_local(monkeypatch): | |
| monkeypatch.delenv("PHOTO_STORAGE_BACKEND", raising=False) | |
| s = get_storage() | |
| assert isinstance(s, LocalDiskStorage) | |
| def test_supabase_backend(monkeypatch): | |
| # Stub boto3 + supply fake credentials so the SupabaseStorage constructor | |
| # doesn't error out on missing env vars or attempt a real S3 client. | |
| import sys, types | |
| fake_boto3 = types.ModuleType("boto3") | |
| fake_boto3.client = lambda *a, **kw: object() # type: ignore[attr-defined] | |
| monkeypatch.setitem(sys.modules, "boto3", fake_boto3) | |
| fake_botocore_client = types.ModuleType("botocore.client") | |
| fake_botocore_client.Config = lambda **kw: object() # type: ignore[attr-defined] | |
| monkeypatch.setitem(sys.modules, "botocore.client", fake_botocore_client) | |
| monkeypatch.setenv("PHOTO_STORAGE_BACKEND", "supabase") | |
| monkeypatch.setenv("SUPABASE_ACCESS_KEY_ID", "ak") | |
| monkeypatch.setenv("SUPABASE_ACCESS_KEY_SECRET", "sk") | |
| monkeypatch.setenv("SUPABASE_ENDPOINT", "https://x.storage.supabase.co/storage/v1/s3") | |
| monkeypatch.setenv("SUPABASE_PHOTO_BUCKET", "user-photos") | |
| s = get_storage() | |
| assert isinstance(s, SupabaseStorage) | |
| def test_unknown_backend_raises(monkeypatch): | |
| monkeypatch.setenv("PHOTO_STORAGE_BACKEND", "azureblobs") | |
| with pytest.raises(ValueError, match="Unknown PHOTO_STORAGE_BACKEND"): | |
| get_storage() | |