"""接口 4:从表 4 取 push_status=0,组装文档报文。不连 Oracle,不发 HTTP。""" from __future__ import annotations from app.outbound.contract_agreement import ( MAX_BATCH, build_contract_agreement_envelope, load_contract_agreement_envelope, ) from app.outbound.memory_repo import MemoryContractAgreementRepo def _row(**overrides): row = { "fid": 300001, "oms_id": 20260928000001, "action_code": 1, "contract_status": 1, "contract_fail_reason": None, "contract_no": "HT1", "agreement_status": None, "agreement_fail_reason": None, "agreement_id": None, "agreement_dtl_id": None, "org_code": "901", "push_status": 0, } row.update(overrides) return row def test_assembles_unpushed_rows_as_document_envelope(): repo = MemoryContractAgreementRepo( [ _row(), _row( fid=300002, action_code=2, contract_status=None, contract_no="HT1", agreement_status=1, agreement_id="AGR1", agreement_dtl_id="AGRD1", ), _row(fid=300003, push_status=1, contract_no="HT-SKIP"), ] ) envelope = load_contract_agreement_envelope(repo) assert envelope == { "data": [ { "fid": 300001, "omsId": 20260928000001, "actionCode": 1, "contractStatus": 1, "contractFailReason": None, "contractNo": "HT1", "agreementStatus": None, "agreementFailReason": None, "agreementId": None, "agreementDtlId": None, "orgCode": "901", }, { "fid": 300002, "omsId": 20260928000001, "actionCode": 2, "contractStatus": None, "contractFailReason": None, "contractNo": "HT1", "agreementStatus": 1, "agreementFailReason": None, "agreementId": "AGR1", "agreementDtlId": "AGRD1", "orgCode": "901", }, ] } assert isinstance(envelope["data"][0]["omsId"], int) def test_oversized_contract_no_group_enters_when_batch_empty(): rows = [ _row(fid=1, oms_id=1, contract_no="HT-BIG"), _row(fid=2, oms_id=2, contract_no="HT-BIG"), _row(fid=3, oms_id=3, contract_no="HT-BIG"), ] envelope = build_contract_agreement_envelope(rows, limit=2) assert [item["fid"] for item in envelope["data"]] == [1, 2, 3] def test_does_not_split_contract_no_when_batch_already_has_rows(): rows = [ _row(fid=1, oms_id=1, contract_no="HT-A"), _row(fid=2, oms_id=2, contract_no="HT-B"), _row(fid=3, oms_id=3, contract_no="HT-B"), ] envelope = build_contract_agreement_envelope(rows, limit=2) assert [item["fid"] for item in envelope["data"]] == [1] def test_empty_contract_no_rows_are_independent(): rows = [ _row(fid=1, oms_id=1, contract_no=None, contract_status=3), _row(fid=2, oms_id=2, contract_no="", contract_status=3), _row(fid=3, oms_id=3, contract_no="HT-C"), ] envelope = build_contract_agreement_envelope(rows, limit=1) assert [item["fid"] for item in envelope["data"]] == [1] def test_batch_cap_is_500(): assert MAX_BATCH == 500 def test_payload_omits_push_status(): item = build_contract_agreement_envelope([_row()])["data"][0] assert "pushStatus" not in item assert "push_status" not in item