DocWeave / backend /test_rules_schema.py
shak3008's picture
feat: complete end-to-end platform with all standout behaviors
fcacf10
Raw
History Blame Contribute Delete
3.03 kB
"""
Tests for rule schema validation.
"""
from app.schemas.rule import RuleCreate, RuleUpdate
import traceback
def test_valid_min_confidence():
r = RuleCreate(
name="Min Confidence",
operator="min_confidence",
configuration={"value": 0.95},
)
assert r.operator == "min_confidence"
assert r.configuration["value"] == 0.95
print("TEST 1 PASS: Valid min_confidence rule")
def test_invalid_min_confidence_value():
try:
RuleCreate(
name="Bad",
operator="min_confidence",
configuration={"value": "not-a-number"},
)
assert False, "Should have raised"
except Exception as e:
assert "numeric" in str(e).lower()
print("TEST 2 PASS: Invalid min_confidence rejected")
def test_min_confidence_out_of_range():
try:
RuleCreate(
name="Bad",
operator="min_confidence",
configuration={"value": 1.5},
)
assert False, "Should have raised"
except Exception as e:
assert "between 0 and 1" in str(e).lower()
print("TEST 3 PASS: Out-of-range min_confidence rejected")
def test_valid_allowed_proposal_types():
r = RuleCreate(
name="Types",
operator="allowed_proposal_types",
configuration={"values": ["CREATE", "UPDATE"]},
)
assert r.configuration["values"] == ["CREATE", "UPDATE"]
print("TEST 4 PASS: Valid allowed_proposal_types")
def test_invalid_allowed_proposal_types():
try:
RuleCreate(
name="Bad Types",
operator="allowed_proposal_types",
configuration={"values": "not-a-list"},
)
assert False, "Should have raised"
except Exception as e:
assert "non-empty" in str(e).lower()
print("TEST 5 PASS: Invalid allowed_proposal_types rejected")
def test_invalid_operator():
try:
RuleCreate(
name="Bad Op",
operator="nonexistent_operator",
configuration={},
)
assert False, "Should have raised"
except Exception as e:
assert "unsupported" in str(e).lower()
print("TEST 6 PASS: Invalid operator rejected")
def test_valid_required_evidence():
r = RuleCreate(
name="Evidence",
operator="required_evidence",
configuration={},
)
assert r.operator == "required_evidence"
print("TEST 7 PASS: Valid required_evidence rule")
def test_update_partial():
r = RuleUpdate(name="Updated Name")
assert r.name == "Updated Name"
assert r.operator is None
print("TEST 8 PASS: Partial update")
test_valid_min_confidence()
test_invalid_min_confidence_value()
test_min_confidence_out_of_range()
test_valid_allowed_proposal_types()
test_invalid_allowed_proposal_types()
test_invalid_operator()
test_valid_required_evidence()
test_update_partial()
print("\n===================================")
print("ALL 8 RULE SCHEMA TESTS PASSED")
print("===================================")