36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
"""
|
|
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)
|