mirror of
https://github.com/rommapp/romm.git
synced 2026-11-29 10:01:00 +01:00
- rename_file links then unlinks, so a name another worker took after the check is refused instead of replaced; filesystems without hard links fall back to rename. - rename_asset owns the whole rename: the thumbnail and asset rows commit in one transaction, and a failed commit moves the files back. - A thumbnail another save or state still resolves is copied for the renamed asset instead of moved away from the other one. - Collection Apply and the visibility switch wait for each other. - The collection settings test builds its fixture with a typed factory, the RSwitch label-slot story uses a colour token, and the moved assets fixture keeps a one-line docstring. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
88 lines
2.2 KiB
Python
88 lines
2.2 KiB
Python
from datetime import timedelta
|
|
|
|
import pytest
|
|
from fastapi.testclient import TestClient
|
|
from main import app
|
|
|
|
from config import (
|
|
OAUTH_ACCESS_TOKEN_EXPIRE_SECONDS,
|
|
OAUTH_REFRESH_TOKEN_EXPIRE_SECONDS,
|
|
)
|
|
from handler.auth import oauth_handler
|
|
from handler.redis_handler import sync_cache
|
|
|
|
|
|
@pytest.fixture
|
|
def client():
|
|
with TestClient(app) as client:
|
|
yield client
|
|
|
|
|
|
@pytest.fixture
|
|
def _isolated_assets_dir(tmp_path, monkeypatch):
|
|
"""Point the shared fs_asset_handler at the test's tmp dir."""
|
|
from pathlib import Path
|
|
|
|
from handler.filesystem import fs_asset_handler
|
|
|
|
new_base = Path(tmp_path).resolve()
|
|
monkeypatch.setattr(fs_asset_handler, "base_path", new_base)
|
|
return new_base
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def clear_cache():
|
|
sync_cache.flushall()
|
|
yield
|
|
sync_cache.flushall()
|
|
|
|
|
|
@pytest.fixture()
|
|
def access_token(admin_user): # noqa
|
|
data = {
|
|
"sub": admin_user.username,
|
|
"iss": "romm:oauth",
|
|
"scopes": " ".join(admin_user.oauth_scopes),
|
|
}
|
|
|
|
return oauth_handler.create_access_token(
|
|
data=data, expires_delta=timedelta(seconds=OAUTH_ACCESS_TOKEN_EXPIRE_SECONDS)
|
|
)
|
|
|
|
|
|
@pytest.fixture()
|
|
def refresh_token(admin_user): # noqa
|
|
data = {
|
|
"sub": admin_user.username,
|
|
"iss": "romm:oauth",
|
|
"scopes": " ".join(admin_user.oauth_scopes),
|
|
}
|
|
|
|
return oauth_handler.create_refresh_token(
|
|
data=data, expires_delta=timedelta(seconds=OAUTH_REFRESH_TOKEN_EXPIRE_SECONDS)
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
def editor_access_token(editor_user): # noqa
|
|
return oauth_handler.create_access_token(
|
|
data={
|
|
"sub": editor_user.username,
|
|
"iss": "romm:oauth",
|
|
"scopes": " ".join(editor_user.oauth_scopes),
|
|
},
|
|
expires_delta=timedelta(seconds=OAUTH_ACCESS_TOKEN_EXPIRE_SECONDS),
|
|
)
|
|
|
|
|
|
@pytest.fixture
|
|
def viewer_access_token(viewer_user): # noqa
|
|
return oauth_handler.create_access_token(
|
|
data={
|
|
"sub": viewer_user.username,
|
|
"iss": "romm:oauth",
|
|
"scopes": " ".join(viewer_user.oauth_scopes),
|
|
},
|
|
expires_delta=timedelta(seconds=OAUTH_ACCESS_TOKEN_EXPIRE_SECONDS),
|
|
)
|