51 lines
1.3 KiB
Python
51 lines
1.3 KiB
Python
from contract_flow_steps import (
|
|
ContractFlowContext,
|
|
begin_date_for,
|
|
check_customer_diligence,
|
|
sign_date_for,
|
|
)
|
|
from errors import DiligenceError
|
|
import pytest
|
|
|
|
|
|
def _ctx(**overrides) -> ContractFlowContext:
|
|
data = dict(
|
|
contract_url="http://example",
|
|
username="u",
|
|
password="p",
|
|
supplier_name="示例",
|
|
order_date="2026-09-28",
|
|
source_type="",
|
|
)
|
|
data.update(overrides)
|
|
return ContractFlowContext(**data)
|
|
|
|
|
|
class _FakeBrowser:
|
|
def __init__(self, text: str):
|
|
self._text = text
|
|
|
|
def read_body_text(self) -> str:
|
|
return self._text
|
|
|
|
|
|
def test_sign_and_begin_fall_back_to_order_date():
|
|
ctx = _ctx()
|
|
assert sign_date_for(ctx) == "2026-09-28"
|
|
assert begin_date_for(ctx) == "2026-09-28"
|
|
|
|
|
|
def test_sign_and_begin_use_contract_dates_when_set():
|
|
ctx = _ctx(contract_sign_date="2026-10-01", contract_start_date="2026-10-02")
|
|
assert sign_date_for(ctx) == "2026-10-01"
|
|
assert begin_date_for(ctx) == "2026-10-02"
|
|
|
|
|
|
def test_diligence_raises_when_page_says_not_done():
|
|
with pytest.raises(DiligenceError, match="客户未尽调"):
|
|
check_customer_diligence(_FakeBrowser("客户未尽调,不能起草"), _ctx())
|
|
|
|
|
|
def test_diligence_passes_when_text_absent():
|
|
check_customer_diligence(_FakeBrowser("客户已尽调"), _ctx())
|