test: 更新 MeSH 打标测试适配 tag_service 重构
- _tag_article → tag_service.tag_article 导入路径 - 增加 name_en 查询 mock 返回值(3 次 execute 调用)
This commit is contained in:
@@ -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()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user