109 lines
3.9 KiB
Python
109 lines
3.9 KiB
Python
"""
|
|
backend/tests/test_shipping_conversation_processing_api.py
|
|
|
|
用途:验收统一 shipping-processing / focus / viewed 工作台 API 信封。
|
|
依赖:Flask 测试客户端、JWT、_seed_run_input、create_order_extraction_run、order_task_service。
|
|
逻辑:Candidate 前仅 order_intake;分配 OT 后可 focus/viewed;旧 /processing GET 已移除。
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from app import db
|
|
from app.core.auth.jwt import issue_local_access_token
|
|
from app.models import ShippingOrderCandidate, ShippingOrderProcessingRun
|
|
from app.services.shipping_notice.order_extraction_run_service import create_order_extraction_run
|
|
from app.services.shipping_notice.order_task_service import (
|
|
allocate_user_task_no_for_run,
|
|
upsert_order_task_from_run,
|
|
)
|
|
from tests.test_shipping_order_extraction_runs import _seed_run_input
|
|
|
|
|
|
def test_workspace_shipping_processing_and_focus_viewed_api(app, client):
|
|
"""Candidate 前仅 intake;形成 OT 后 focus/viewed 可用。"""
|
|
with app.app_context():
|
|
user, agent, session, intake, document = _seed_run_input(suffix='API-PROC')
|
|
run, _ = create_order_extraction_run(
|
|
user=user,
|
|
agent_id=agent.id,
|
|
conversation_id=session.session_id,
|
|
intake_nos=[intake.intake_no],
|
|
keep_input_open=True,
|
|
)
|
|
db.session.commit()
|
|
token = issue_local_access_token(user)
|
|
session_id = session.session_id
|
|
intake_no = intake.intake_no
|
|
run_id = int(run.id)
|
|
intake_id = int(intake.id)
|
|
document_id = int(document.id)
|
|
assert run.user_task_no is None
|
|
|
|
headers = {'Authorization': f'Bearer {token}'}
|
|
processing = client.get(
|
|
f'/api/workspace/shipping-processing/conversations/{session_id}',
|
|
headers=headers,
|
|
)
|
|
assert processing.status_code == 200, processing.get_json()
|
|
body = processing.get_json()
|
|
assert body['success'] is True
|
|
work_items = body['data'].get('work_items') or []
|
|
assert any(
|
|
str(row.get('work_item_type') or '') == 'order_intake'
|
|
and str(row.get('work_item_no') or '') == intake_no
|
|
for row in work_items
|
|
if isinstance(row, dict)
|
|
)
|
|
assert not any(
|
|
str(row.get('work_item_type') or '') == 'order_task'
|
|
for row in work_items
|
|
if isinstance(row, dict)
|
|
)
|
|
|
|
legacy = client.get(
|
|
f'/api/workspace/shipping-notice/conversations/{session_id}/processing',
|
|
headers=headers,
|
|
)
|
|
assert legacy.status_code == 404
|
|
|
|
with app.app_context():
|
|
run = db.session.get(ShippingOrderProcessingRun, run_id)
|
|
assert run is not None
|
|
candidate = ShippingOrderCandidate(
|
|
candidate_no=f'SNC-API-PROC-{run_id}',
|
|
intake_id=intake_id,
|
|
primary_document_id=document_id,
|
|
candidate_key=f'key-api-proc-{run_id}',
|
|
order_extraction_run_id=run_id,
|
|
is_current_version=True,
|
|
candidate_status='provisional',
|
|
structured_result_json={},
|
|
)
|
|
db.session.add(candidate)
|
|
db.session.flush()
|
|
allocate_user_task_no_for_run(run)
|
|
upsert_order_task_from_run(
|
|
run,
|
|
intake_id=intake_id,
|
|
candidate_id=int(candidate.id),
|
|
source_type='direct_pdf',
|
|
stage='candidate_created',
|
|
)
|
|
db.session.commit()
|
|
user_task_no = str(run.user_task_no)
|
|
|
|
focus = client.post(
|
|
f'/api/workspace/shipping-notice/conversation-tasks/{user_task_no}/focus',
|
|
json={'conversation_id': session_id},
|
|
headers=headers,
|
|
)
|
|
assert focus.status_code == 200, focus.get_json()
|
|
assert focus.get_json()['data']['focused_task_no'] == user_task_no
|
|
|
|
viewed = client.post(
|
|
f'/api/workspace/shipping-notice/conversation-tasks/{user_task_no}/viewed',
|
|
json={'conversation_id': session_id},
|
|
headers=headers,
|
|
)
|
|
assert viewed.status_code == 200, viewed.get_json()
|