35 lines
1.2 KiB
Python
35 lines
1.2 KiB
Python
from copy import deepcopy
|
|
from pathlib import Path
|
|
|
|
import pytest
|
|
from pydantic import ValidationError
|
|
|
|
from ai_platform.presentation.http.admin_tenant_key_routes import TenantKeySecret
|
|
from ai_platform.presentation.http.schemas import RunRequest
|
|
|
|
FIXTURE_DIR = Path(__file__).resolve().parents[1] / "contracts/lead-scoring/v2/fixtures"
|
|
|
|
|
|
def test_web_fixture_matches_run_request_contract():
|
|
RunRequest.model_validate_json((FIXTURE_DIR / "run-request.json").read_text(encoding="utf-8"))
|
|
|
|
|
|
def test_tenant_key_provision_fixture_matches_one_time_response():
|
|
TenantKeySecret.model_validate_json(
|
|
(FIXTURE_DIR / "tenant-key-provision-response.json").read_text(encoding="utf-8")
|
|
)
|
|
|
|
|
|
def test_run_request_contains_caller_rules_and_weights(valid_run_payload):
|
|
request = RunRequest.model_validate(valid_run_payload)
|
|
assert request.scoring_config.rules[0].points == 25
|
|
assert request.scoring_config.ai_weight == 0
|
|
|
|
|
|
def test_run_request_requires_weights_to_sum_to_one(valid_run_payload):
|
|
data = deepcopy(valid_run_payload)
|
|
data["scoring_config"].update(rule_weight=0.5, ai_weight=0.4)
|
|
|
|
with pytest.raises(ValidationError):
|
|
RunRequest.model_validate(data)
|