diff --git a/tests/integration/test_assets_api.py b/tests/integration/test_assets_api.py index d15ef7df1..8fe4ff33f 100755 --- a/tests/integration/test_assets_api.py +++ b/tests/integration/test_assets_api.py @@ -103,19 +103,35 @@ class StubAssetRepository: def find_by_id(self, asset_id: str) -> Asset | None: return self._assets.get(asset_id) - def find_by_library(self, library_id: str, skip: int = 0, limit: int = 100) -> list[Asset]: + def find_by_library( + self, library_id: str, skip: int = 0, limit: int = 100, status: list[str] | None = None + ) -> list[Asset]: items = [a for a in self._assets.values() if a.library_id == library_id] + if status: + items = [a for a in items if a.status.value in status] + items.sort(key=lambda a: a.created_at, reverse=True) return items[skip : skip + limit] - def find_by_library_and_file_type(self, library_id: str, file_type: str) -> list[Asset]: - return [ + def find_by_library_and_file_type( + self, library_id: str, file_type: str, skip: int = 0, limit: int = 100, status: list[str] | None = None + ) -> list[Asset]: + items = [ a for a in self._assets.values() if a.library_id == library_id and a.mime_type and a.mime_type.startswith(file_type) ] + if status: + items = [a for a in items if a.status.value in status] + items.sort(key=lambda a: a.created_at, reverse=True) + return items[skip : skip + limit] - def find_by_project(self, project_id: str, skip: int = 0, limit: int = 100) -> list[Asset]: + def find_by_project( + self, project_id: str, skip: int = 0, limit: int = 100, status: list[str] | None = None + ) -> list[Asset]: items = [a for a in self._assets.values() if a.project_id == project_id] + if status: + items = [a for a in items if a.status.value in status] + items.sort(key=lambda a: a.created_at, reverse=True) return items[skip : skip + limit] def update(self, asset: Asset) -> Asset: @@ -184,11 +200,17 @@ class StubAssetRepository: count += 1 return count - def count_by_project(self, project_id: str) -> int: - return len([a for a in self._assets.values() if a.project_id == project_id]) + def count_by_project(self, project_id: str, status: list[str] | None = None) -> int: + items = [a for a in self._assets.values() if a.project_id == project_id] + if status: + items = [a for a in items if a.status.value in status] + return len(items) - def count_by_project_ids(self, project_ids: list[str]) -> int: - return len([a for a in self._assets.values() if a.project_id in project_ids]) + def count_by_project_ids(self, project_ids: list[str], status: list[str] | None = None) -> int: + items = [a for a in self._assets.values() if a.project_id in project_ids] + if status: + items = [a for a in items if a.status.value in status] + return len(items) def find_by_library_and_file_hash(self, library_id: str, file_hash: str) -> Asset | None: if not file_hash: @@ -395,7 +417,7 @@ class TestListAssets: """获取素材列表端点测试。""" def _create_test_assets(self, client, count: int = 3): - """辅助方法:创建测试素材。""" + """辅助方法:创建测试素材(status=ready)。""" for i in range(count): client.post( "/api/v1/assets", @@ -406,6 +428,7 @@ class TestListAssets: "storage_key": f"uploads/video-{i}.mp4", "mime_type": "video/mp4", "file_size": 1024 * (i + 1), + "status": "ready", }, ) @@ -457,6 +480,7 @@ class TestListAssets: "name": "hello-world.mp4", "storage_key": "uploads/hello.mp4", "mime_type": "video/mp4", + "status": "ready", }, ) client.post( @@ -467,6 +491,7 @@ class TestListAssets: "name": "goodbye.mp4", "storage_key": "uploads/goodbye.mp4", "mime_type": "video/mp4", + "status": "ready", }, ) @@ -768,6 +793,7 @@ class TestAssetsCRUDFlow: "mime_type": "video/mp4", "file_size": 8192, "metadata": {"source": "test"}, + "status": "ready", }, ) assert create_resp.status_code == 200