From 4a24f764f7b5845eea18a2b672318a14534a79a8 Mon Sep 17 00:00:00 2001 From: "34047007@qq.com" <34047007@qq.com> Date: Mon, 27 Jul 2026 16:16:43 +0800 Subject: [PATCH] =?UTF-8?q?test:=20=E6=9B=B4=E6=96=B0=20MeSH=20=E6=89=93?= =?UTF-8?q?=E6=A0=87=E6=B5=8B=E8=AF=95=E9=80=82=E9=85=8D=20tag=5Fservice?= =?UTF-8?q?=20=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - _tag_article → tag_service.tag_article 导入路径 - 增加 name_en 查询 mock 返回值(3 次 execute 调用) --- backend/tests/test_service_pubmed_api.py | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/backend/tests/test_service_pubmed_api.py b/backend/tests/test_service_pubmed_api.py index f420ed5..2c6b8ea 100644 --- a/backend/tests/test_service_pubmed_api.py +++ b/backend/tests/test_service_pubmed_api.py @@ -155,9 +155,9 @@ async def test_tag_article_no_mesh(): """Empty mesh_headings -> returns 0""" db = AsyncMock() - from app.services.pubmed_api import _tag_article + from app.services.tag_service import tag_article - result = await _tag_article(db, uuid.uuid4(), []) + result = await tag_article(db, uuid.uuid4(), []) assert result == 0 @@ -166,9 +166,9 @@ async def test_tag_article_no_mesh_ui(): """Mesh headings without UI values -> returns 0""" db = AsyncMock() - from app.services.pubmed_api import _tag_article + from app.services.tag_service import tag_article - result = await _tag_article( + result = await tag_article( db, uuid.uuid4(), [{"descriptor": "Cancer", "ui": "", "major": False}], ) @@ -188,15 +188,17 @@ async def test_tag_article_matches_tags(): mock_match = MagicMock() mock_match.scalars.return_value.all.return_value = [mock_tag] - mock_empty = MagicMock() - mock_empty.scalar.return_value = None - db.execute.side_effect = [mock_match, mock_empty] + mock_no_name = MagicMock() + mock_no_name.scalars.return_value.all.return_value = [] + mock_no_existing = MagicMock() + mock_no_existing.all.return_value = [] + db.execute.side_effect = [mock_match, mock_no_name, mock_no_existing] mesh_headings = [{"descriptor": "Cancer", "ui": "D000001", "major": True}] - from app.services.pubmed_api import _tag_article + from app.services.tag_service import tag_article - result = await _tag_article(db, lit_id, mesh_headings) + result = await tag_article(db, lit_id, mesh_headings) assert result == 1 db.add.assert_called_once() @@ -213,9 +215,9 @@ async def test_tag_article_no_match(): mesh_headings = [{"descriptor": "RareDisease", "ui": "D999999", "major": False}] - from app.services.pubmed_api import _tag_article + from app.services.tag_service import tag_article - result = await _tag_article(db, lit_id, mesh_headings) + result = await tag_article(db, lit_id, mesh_headings) assert result == 0 db.add.assert_not_called()