76 lines
2.6 KiB
Python
76 lines
2.6 KiB
Python
# ORA 码和约束名:按约束区分接口 1 / 接口 3 重复,未知唯一约束不当成 oms_id 重复。
|
||
|
||
from __future__ import annotations
|
||
|
||
from rpa_oracle.errors import (
|
||
is_contract_fid_duplicate,
|
||
is_sales_oms_id_duplicate,
|
||
ora_code,
|
||
ora_constraint,
|
||
)
|
||
|
||
|
||
# 构造带 oracledb 风格 args[0].code / .message 的假异常。
|
||
def _ora(code: int, message: str) -> Exception:
|
||
# oracledb 异常 args[0] 的替身,只带 code 和 message。
|
||
class Info:
|
||
pass
|
||
|
||
info = Info()
|
||
info.code = code
|
||
info.message = message
|
||
exc = Exception()
|
||
exc.args = (info,)
|
||
return exc
|
||
|
||
|
||
# 表 1 oms_id 唯一约束 ORA-00001 识别为接口 1 重复。
|
||
def test_uk_rpa_sgmd_oms_id_is_sales_duplicate():
|
||
exc = _ora(1, "ORA-00001: unique constraint (RPAINIT.UK_RPA_SGMD_OMS_ID) violated")
|
||
assert ora_code(exc) == 1
|
||
assert ora_constraint(exc) == "UK_RPA_SGMD_OMS_ID"
|
||
assert is_sales_oms_id_duplicate(exc)
|
||
assert not is_contract_fid_duplicate(exc)
|
||
|
||
|
||
# 表 3 fid 主键 ORA-00001 识别为接口 3 重复。
|
||
def test_pk_rpa_pcd_is_contract_fid_duplicate():
|
||
exc = _ora(1, "ORA-00001: unique constraint (RPAINIT.PK_RPA_PCD) violated")
|
||
assert ora_code(exc) == 1
|
||
assert ora_constraint(exc) == "PK_RPA_PCD"
|
||
assert is_contract_fid_duplicate(exc)
|
||
assert not is_sales_oms_id_duplicate(exc)
|
||
|
||
|
||
# 未知唯一约束不当成 oms_id 重复。
|
||
def test_unknown_unique_constraint_is_not_oms_id_duplicate():
|
||
exc = _ora(1, "ORA-00001: unique constraint (RPAINIT.UK_SOMETHING_ELSE) violated")
|
||
assert ora_code(exc) == 1
|
||
assert ora_constraint(exc) == "UK_SOMETHING_ELSE"
|
||
assert not is_sales_oms_id_duplicate(exc)
|
||
assert not is_contract_fid_duplicate(exc)
|
||
|
||
|
||
# 只有 ORA-00001、没有约束名时,不当成 oms_id 重复。
|
||
def test_ora_00001_without_constraint_name_is_not_oms_id_duplicate():
|
||
exc = _ora(1, "ORA-00001: unique constraint violated")
|
||
assert ora_code(exc) == 1
|
||
assert ora_constraint(exc) is None
|
||
assert not is_sales_oms_id_duplicate(exc)
|
||
assert not is_contract_fid_duplicate(exc)
|
||
|
||
|
||
# 约束名大小写不影响接口 1 重复判定。
|
||
def test_constraint_match_is_case_insensitive():
|
||
exc = _ora(1, "ORA-00001: unique constraint (rpainit.uk_rpa_sgmd_oms_id) violated")
|
||
assert is_sales_oms_id_duplicate(exc)
|
||
|
||
|
||
# 非 ORA-00001 不当成重复。
|
||
def test_non_unique_error_is_not_duplicate():
|
||
exc = _ora(12170, "ORA-12170: TNS:Connect timeout occurred")
|
||
assert ora_code(exc) == 12170
|
||
assert ora_constraint(exc) is None
|
||
assert not is_sales_oms_id_duplicate(exc)
|
||
assert not is_contract_fid_duplicate(exc)
|