"""合同附件:没传不动,显式空数组清空。""" from decimal import Decimal from types import SimpleNamespace from app.crud.crm.contract import _apply_contract_entity_fields _STORED = '[{"ossId":"/contract/a.pdf","category":"scan"}]' def _entity(): return SimpleNamespace( attachment_files=_STORED, customer_id="", contact_id=None, owner_user_id=None, status="executing", tax_rate=None, received_amount=Decimal("0"), invoice_amount=Decimal("0"), amount=Decimal("1"), ) def test_omitted_attachment_files_are_left_unchanged(): entity = _entity() _apply_contract_entity_fields(entity, {"remark": "只改备注"}, db=None, tenant_no="t", is_create=False) assert entity.attachment_files == _STORED def test_explicit_empty_attachment_values_clear_the_field(): for empty in ("[]", "", []): entity = _entity() _apply_contract_entity_fields( entity, {"attachmentFiles": empty}, db=None, tenant_no="t", is_create=False ) assert entity.attachment_files == "[]"