refactor(kb): 重构kb api
This commit is contained in:
1 parent
b476b58a91
commit
d5e76dee36
30 files changed
+2713
-1691
No files matched your search
@@ -0,0 +1,35 @@
|
||||
"""
|
||||
tests/jobs/test_queue.py
|
||||
|
||||
用途:验证 jobs 入队 compat 包装与 JobType.enqueue。
|
||||
"""
|
||||
from unittest.mock import patch
|
||||
|
||||
from app.jobs import JobType, enqueue, enqueue_clean_job, enqueue_kb_job
|
||||
from app.core.errors import ValidationError
|
||||
|
||||
|
||||
def test_enqueue_kb_job_delegates(app):
|
||||
with app.app_context():
|
||||
with patch('app.services.knowledge_cleaning.queue_service.enqueue_kb_job', return_value=(True, 'queued_for_worker')) as mocked:
|
||||
ok, msg = enqueue_kb_job(42)
|
||||
assert ok is True
|
||||
assert msg == 'queued_for_worker'
|
||||
mocked.assert_called_once_with(42)
|
||||
|
||||
|
||||
def test_enqueue_clean_job_alias(app):
|
||||
with app.app_context():
|
||||
with patch('app.jobs.queue.enqueue_kb_job', return_value=(True, 'queued_manual')) as mocked:
|
||||
ok, msg = enqueue_clean_job(7)
|
||||
assert ok is True
|
||||
mocked.assert_called_once_with(7)
|
||||
|
||||
|
||||
def test_enqueue_requires_job_id(app):
|
||||
with app.app_context():
|
||||
try:
|
||||
enqueue(JobType.KB_CLEAN, {})
|
||||
assert False, 'expected ValidationError'
|
||||
except ValidationError as exc:
|
||||
assert 'job_id' in str(exc)
|
||||
Reference in new issue
Block a user