test(shipping): 更新订单复核库存与通知流程测试
This commit is contained in:
1 parent
8ec028e6a3
commit
265a6e179a
168 files changed
+9420
-4613
No files matched your search
@@ -21,6 +21,7 @@ from app.models import (
|
||||
ShippingOrderDocument,
|
||||
ShippingOrderIntake,
|
||||
ShippingNotice,
|
||||
ShippingOrderTask,
|
||||
User,
|
||||
)
|
||||
from app.services.shipping_notice.business_fingerprint import (
|
||||
@@ -88,6 +89,106 @@ def _seed_parsed_intake(
|
||||
return asset, intake
|
||||
|
||||
|
||||
def _seed_existing_notice_task(
|
||||
user_id: int,
|
||||
*,
|
||||
task_no: str,
|
||||
business_fingerprint: str,
|
||||
fingerprint_version: str,
|
||||
content_fingerprint: str | None = None,
|
||||
content_fingerprint_version: str | None = None,
|
||||
source_content_hash: str | None = None,
|
||||
document_version: int = 1,
|
||||
) -> ShippingNotice:
|
||||
"""
|
||||
构造一个已建单的正式发货通知,作为业务指纹去重的命中目标。
|
||||
|
||||
新契约:ShippingNotice 不再保存指纹投影;business/content 指纹转移到被消费的
|
||||
ShippingOrderCandidate(consumed_task_id -> 建单前 OT),Notice 经 order_task_id
|
||||
挂接该 OT。只有建立 Notice→Task→Candidate 这条链,duplicate_detection 的
|
||||
Notice→Task(consumed_task_id)→Candidate 查询才能命中——这是 key 断言,
|
||||
不是只为了消除构造参数,而是让「已有任务重复」真正可被探测。
|
||||
"""
|
||||
ot = ShippingOrderTask(
|
||||
task_no=f'OT-{task_no}',
|
||||
user_id=user_id,
|
||||
source_type='eml',
|
||||
lifecycle_status='active',
|
||||
)
|
||||
db.session.add(ot)
|
||||
db.session.flush()
|
||||
|
||||
asset = FileAsset(
|
||||
asset_no=f'FA-{task_no}',
|
||||
owner_user_id=user_id,
|
||||
original_filename='existing.txt',
|
||||
storage_provider='minio',
|
||||
storage_bucket='hxops-file-assets',
|
||||
storage_key=f'temporary/{user_id}/{task_no}.txt',
|
||||
content_hash=source_content_hash or f'hash-{task_no}',
|
||||
file_size=1,
|
||||
mime_type='text/plain',
|
||||
upload_status='ready',
|
||||
lifecycle_status='temporary',
|
||||
)
|
||||
db.session.add(asset)
|
||||
db.session.flush()
|
||||
|
||||
intake = ShippingOrderIntake(
|
||||
intake_no=f'SNI-{task_no}',
|
||||
asset_id=asset.id,
|
||||
user_id=user_id,
|
||||
purpose='shipping_notice',
|
||||
parse_status='parsed',
|
||||
parser_version='v1',
|
||||
duplicate_status='none',
|
||||
)
|
||||
db.session.add(intake)
|
||||
db.session.flush()
|
||||
|
||||
doc = ShippingOrderDocument(
|
||||
intake_id=intake.id,
|
||||
attachment_key=f'att-{task_no}',
|
||||
document_type='attachment',
|
||||
filename=f'{task_no}.pdf',
|
||||
content_hash=source_content_hash or f'hash-{task_no}',
|
||||
classification='order_notice',
|
||||
parse_status='parsed',
|
||||
)
|
||||
db.session.add(doc)
|
||||
db.session.flush()
|
||||
|
||||
candidate = ShippingOrderCandidate(
|
||||
candidate_no=f'SNC-{task_no}',
|
||||
intake_id=intake.id,
|
||||
primary_document_id=doc.id,
|
||||
candidate_key=f'test:{task_no}',
|
||||
business_fingerprint=business_fingerprint,
|
||||
fingerprint_version=fingerprint_version,
|
||||
content_fingerprint=content_fingerprint,
|
||||
content_fingerprint_version=content_fingerprint_version,
|
||||
consumed_task_id=ot.id,
|
||||
duplicate_status='none',
|
||||
candidate_status='accepted',
|
||||
selected=True,
|
||||
)
|
||||
db.session.add(candidate)
|
||||
db.session.flush()
|
||||
ot.candidate_id = candidate.id
|
||||
|
||||
notice = ShippingNotice(
|
||||
task_no=task_no,
|
||||
user_id=user_id,
|
||||
source_type='manual',
|
||||
document_version=document_version,
|
||||
order_task_id=ot.id,
|
||||
lifecycle_status='active',
|
||||
)
|
||||
db.session.add(notice)
|
||||
db.session.commit()
|
||||
return notice
|
||||
|
||||
|
||||
def test_business_fingerprint_ignores_internal_hex_reservation_id():
|
||||
"""内部 32 位 hex 不得增强业务身份指纹,避免把数据库主键当成订单真值。"""
|
||||
summary = {
|
||||
@@ -185,16 +286,13 @@ def test_pending_review_hit_is_same_active_blocking(app, dedup_user):
|
||||
business_summary=summary,
|
||||
fingerprint=fp,
|
||||
)
|
||||
existing = ShippingNotice(
|
||||
_seed_existing_notice_task(
|
||||
dedup_user.id,
|
||||
task_no='SN-PENDING-1',
|
||||
user_id=dedup_user.id,
|
||||
source_type='manual',
|
||||
business_fingerprint=fp['fingerprint'],
|
||||
fingerprint_version=fp['version'],
|
||||
document_version=1,
|
||||
)
|
||||
db.session.add(existing)
|
||||
db.session.commit()
|
||||
|
||||
result = detect_duplicates_for_intake(
|
||||
intake=intake,
|
||||
@@ -250,15 +348,13 @@ def test_candidate_duplicate_blocks_only_matching_candidate(app, dedup_user):
|
||||
'lines': [],
|
||||
}
|
||||
)
|
||||
existing = ShippingNotice(
|
||||
_seed_existing_notice_task(
|
||||
dedup_user.id,
|
||||
task_no='SN-EXISTING-PO-A',
|
||||
user_id=dedup_user.id,
|
||||
source_type='manual',
|
||||
business_fingerprint=existing_fp['fingerprint'],
|
||||
fingerprint_version=existing_fp['version'],
|
||||
source_content_hash='hash-other-file',
|
||||
)
|
||||
db.session.add(existing)
|
||||
|
||||
parent = FileAsset(
|
||||
asset_no='FA-STAGE2-DEDUP-EML',
|
||||
@@ -372,15 +468,13 @@ def test_refresh_duplicate_updates_candidate_statuses(app, dedup_user):
|
||||
'lines': [],
|
||||
}
|
||||
)
|
||||
existing = ShippingNotice(
|
||||
_seed_existing_notice_task(
|
||||
dedup_user.id,
|
||||
task_no='SN-REFRESH-EXISTING',
|
||||
user_id=dedup_user.id,
|
||||
source_type='manual',
|
||||
business_fingerprint=existing_fp['fingerprint'],
|
||||
fingerprint_version=existing_fp['version'],
|
||||
source_content_hash='hash-refresh-other',
|
||||
)
|
||||
db.session.add(existing)
|
||||
|
||||
parent = FileAsset(
|
||||
asset_no='FA-REFRESH-DEDUP',
|
||||
@@ -479,16 +573,14 @@ def test_candidate_content_fingerprint_distinguishes_same_content_and_revision(a
|
||||
}
|
||||
identity = build_business_fingerprint(base)
|
||||
content = build_content_fingerprint(base)
|
||||
existing = ShippingNotice(
|
||||
_seed_existing_notice_task(
|
||||
dedup_user.id,
|
||||
task_no='SN-CONTENT-EXISTING',
|
||||
user_id=dedup_user.id,
|
||||
source_type='manual',
|
||||
business_fingerprint=identity['fingerprint'],
|
||||
fingerprint_version=identity['version'],
|
||||
content_fingerprint=content['fingerprint'],
|
||||
content_fingerprint_version=content['version'],
|
||||
)
|
||||
db.session.add(existing)
|
||||
parent, intake = _seed_parsed_intake(
|
||||
dedup_user.id,
|
||||
intake_no='SNI-CONTENT-CHECK',
|
||||
|
||||
Reference in new issue
Block a user