From 24f3726314ff17fc5507b6bbe81b1c032d156eeb Mon Sep 17 00:00:00 2001 From: CI Bot Date: Sat, 18 Jul 2026 18:41:49 +0800 Subject: [PATCH] =?UTF-8?q?fix(test):=20=E9=9B=86=E6=88=90=E6=B5=8B?= =?UTF-8?q?=E8=AF=95StubAssetRepository=E5=A2=9E=E5=8A=A0status=E5=8F=82?= =?UTF-8?q?=E6=95=B0+=E7=B4=A0=E6=9D=90=E9=BB=98=E8=AE=A4ready?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - StubAssetRepository的find/count方法增加status可选参数 - 列表测试创建的素材改为status=ready,匹配默认过滤规则 - 补充按created_at倒序排序,与真实实现行为一致 --- tests/integration/test_assets_api.py | 44 ++++++++++++++++++++++------ 1 file changed, 35 insertions(+), 9 deletions(-) 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