Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions api/peacock_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,44 @@

_FORBIDDEN_WEBHOOK_HOST_FRAGMENTS = ("abvetos.com",)

PILOT_COLLECTION: dict[str, dict[str, float]] = {
"eg0": { # Silk Haussmann
"drapeCoefficient": 0.85,
"weightGSM": 60,
"elasticityPct": 12,
"recoveryPct": 95,
"frictionCoefficient": 0.22,
},
"eg1": { # Business Elite (Cotton/Wool)
"drapeCoefficient": 0.35,
"weightGSM": 280,
"elasticityPct": 4,
"recoveryPct": 80,
"frictionCoefficient": 0.65,
},
"eg2": { # Velvet Night
"drapeCoefficient": 0.55,
"weightGSM": 320,
"elasticityPct": 8,
"recoveryPct": 88,
"frictionCoefficient": 0.45,
},
"eg3": { # Tech Shell
"drapeCoefficient": 0.15,
"weightGSM": 180,
"elasticityPct": 2,
"recoveryPct": 98,
"frictionCoefficient": 0.75,
},
"eg4": { # Cashmere Cloud
"drapeCoefficient": 0.70,
"weightGSM": 220,
"elasticityPct": 15,
"recoveryPct": 92,
"frictionCoefficient": 0.30,
},
}


def is_webhook_destination_forbidden(url: str) -> bool:
"""True si la URL apunta a un host no permitido para webhooks salientes."""
Expand Down
45 changes: 44 additions & 1 deletion tests/test_peacock_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,50 @@
if _API not in sys.path:
sys.path.insert(0, _API)

from peacock_core import ZERO_SIZE_LATENCY_BUDGET_MS, is_webhook_destination_forbidden
from peacock_core import PILOT_COLLECTION, ZERO_SIZE_LATENCY_BUDGET_MS, is_webhook_destination_forbidden

_PILOT_KEYS = {"drapeCoefficient", "weightGSM", "elasticityPct", "recoveryPct", "frictionCoefficient"}


class TestPilotCollection(unittest.TestCase):
def test_has_five_entries(self) -> None:
self.assertEqual(len(PILOT_COLLECTION), 5)

def test_all_ids_present(self) -> None:
for key in ("eg0", "eg1", "eg2", "eg3", "eg4"):
self.assertIn(key, PILOT_COLLECTION)

def test_each_entry_has_required_keys(self) -> None:
for fabric_id, props in PILOT_COLLECTION.items():
self.assertEqual(
set(props.keys()),
_PILOT_KEYS,
msg=f"Fabric entry '{fabric_id}' is missing required keys",
)

def test_all_values_are_numeric(self) -> None:
for fabric_id, props in PILOT_COLLECTION.items():
for k, v in props.items():
self.assertIsInstance(
v, (int, float),
msg=f"PILOT_COLLECTION['{fabric_id}']['{k}'] is not numeric",
)

def test_eg0_silk_haussmann_values(self) -> None:
eg0 = PILOT_COLLECTION["eg0"]
self.assertAlmostEqual(eg0["drapeCoefficient"], 0.85)
self.assertAlmostEqual(eg0["weightGSM"], 60)
self.assertAlmostEqual(eg0["elasticityPct"], 12)
self.assertAlmostEqual(eg0["recoveryPct"], 95)
self.assertAlmostEqual(eg0["frictionCoefficient"], 0.22)

def test_eg3_tech_shell_has_lowest_drape(self) -> None:
drapes = {k: v["drapeCoefficient"] for k, v in PILOT_COLLECTION.items()}
self.assertEqual(min(drapes, key=drapes.get), "eg3")

def test_eg4_cashmere_cloud_highest_elasticity(self) -> None:
elasticities = {k: v["elasticityPct"] for k, v in PILOT_COLLECTION.items()}
self.assertEqual(max(elasticities, key=elasticities.get), "eg4")


class TestPeacockCoreIntegration(unittest.TestCase):
Expand Down