102 lines
3.2 KiB
Python
102 lines
3.2 KiB
Python
from state_center.app.m5_client import (
|
||
evaluate_priority_source,
|
||
load_connection,
|
||
lookup_params,
|
||
recorded_source_rows,
|
||
)
|
||
|
||
|
||
def test_lookup_params_use_the_single_fujian_row():
|
||
params = lookup_params()
|
||
assert params["goodsNameLike"] == "%哈药牌%"
|
||
assert params["approvalNo"] == "食健备G201923000558"
|
||
assert params["spec"] == "10ml*90支"
|
||
assert params["manufacturer"] == "哈药集团三精制药有限公司"
|
||
assert params["entryId"] == 907
|
||
assert params["expectedGoodsId"] == "4000109983"
|
||
assert "PUB_ENTRY_GOODS_V" in params["sql"]
|
||
assert "PRODAREA" not in params["sql"].split("WHERE", 1)[1]
|
||
|
||
|
||
def test_m5_host_defaults_and_password_stays_out_of_repo(monkeypatch):
|
||
monkeypatch.delenv("M5_USER", raising=False)
|
||
monkeypatch.delenv("M5_PASSWORD", raising=False)
|
||
monkeypatch.delenv("M5_SERVICE", raising=False)
|
||
cfg = load_connection()
|
||
assert cfg["host"] == "173.1.1.215"
|
||
assert cfg["port"] == 1521
|
||
assert cfg["serviceName"] == "m5"
|
||
assert cfg["password"] == ""
|
||
|
||
|
||
def test_priority_1_matching_spec_skips_source_add():
|
||
judged = evaluate_priority_source(
|
||
[
|
||
{
|
||
"ENTRYID": 907,
|
||
"PRIORITY": 1,
|
||
"GOODSTYPE": "10ml*90支",
|
||
"FACTORYNAME": "哈药集团三精制药有限公司",
|
||
}
|
||
],
|
||
entry_id=907,
|
||
spec="10ml*90支",
|
||
manufacturer="哈药集团三精制药有限公司",
|
||
)
|
||
assert judged["source_add_needed"] is False
|
||
|
||
|
||
def test_priority_1_other_spec_needs_source_add():
|
||
judged = evaluate_priority_source(
|
||
[
|
||
{
|
||
"ENTRYID": 907,
|
||
"PRIORITY": 1,
|
||
"GOODSTYPE": "10ml*10支",
|
||
"FACTORYNAME": "哈药集团三精制药有限公司",
|
||
}
|
||
],
|
||
entry_id=907,
|
||
spec="10ml*90支",
|
||
manufacturer="哈药集团三精制药有限公司",
|
||
)
|
||
assert judged["source_add_needed"] is True
|
||
|
||
|
||
def test_lookup_params_include_source_sql():
|
||
params = lookup_params()
|
||
assert "bms_su_supplygoods_doc_v" in params["sourceSql"]
|
||
assert params["expectedSourceAddNeeded"] is False
|
||
|
||
|
||
def test_recorded_source_rows_cover_hayao_without_m5():
|
||
rows = recorded_source_rows("4000109983")
|
||
assert rows is not None
|
||
judged = evaluate_priority_source(
|
||
rows,
|
||
entry_id=907,
|
||
spec="10ml*90支",
|
||
manufacturer="哈药集团三精制药有限公司",
|
||
)
|
||
assert judged["source_add_needed"] is False
|
||
assert recorded_source_rows("other") is None
|
||
|
||
|
||
def test_hayao_priority1_sql_row_skips_source_add():
|
||
"""第二条 SQL 的真实结果:907 / 1 / 10ml*90支 / 哈药集团三精制药有限公司。"""
|
||
judged = evaluate_priority_source(
|
||
[
|
||
{
|
||
"ENTRYID": 907,
|
||
"PRIORITY": 1,
|
||
"GOODSTYPE": "10ml*90支",
|
||
"FACTORYNAME": "哈药集团三精制药有限公司",
|
||
}
|
||
],
|
||
entry_id=907,
|
||
spec="10ml*90支",
|
||
manufacturer="哈药集团三精制药有限公司",
|
||
)
|
||
assert judged["source_add_needed"] is False
|
||
assert judged["hit"]["ENTRYID"] == 907
|