Coverage for src/case_router/seed.py: 100%

11 statements  

« prev     ^ index     » next       coverage.py v7.16.2, created at 2026-10-12 18:59 +0000

1"""Two demo tenants with different routing rules, to show per-org configuration.""" 

2 

3from __future__ import annotations 

4 

5from .db import Database, RuleRepository, RuleRow, TenantRepository 

6from .models import Tenant 

7 

8DEMO_TENANTS: dict[Tenant, list[RuleRow]] = { 

9 Tenant("acme", "Acme Outfitters", requests_per_minute=120): [ 

10 RuleRow("priority", "CRITICAL", "Escalations"), 

11 RuleRow("keyword", "refund,invoice,charge,billing", "Billing"), 

12 RuleRow("tier", "PREMIUM", "Premium Support"), 

13 RuleRow("channel", "PHONE", "Phone Desk"), 

14 RuleRow("any", "", "General Support"), 

15 ], 

16 Tenant("globex", "Globex Logistics", requests_per_minute=60): [ 

17 RuleRow("keyword", "outage,down,offline", "Incident Response"), 

18 RuleRow("priority", "HIGH", "Priority Desk"), 

19 RuleRow("any", "", "Service Desk"), 

20 ], 

21} 

22 

23 

24def seed_demo_data(db: Database) -> None: 

25 """Add the demo tenants. Safe to run again: existing rules are left alone.""" 

26 tenants = TenantRepository(db) 

27 rules = RuleRepository(db) 

28 for tenant, rows in DEMO_TENANTS.items(): 

29 tenants.save(tenant) 

30 if not rules.for_tenant(tenant.id): 

31 rules.replace(tenant.id, rows)