ifixkart-backend/swarm/tests/test_scenarios.py

85 lines
3.3 KiB
Python

"""
Unit Tests: 4 Core Business Simulation Scenarios
"""
import sys
sys.path.insert(0, '/mnt/fam/SERVER/IfixKartEcommerce/Backend')
sys.path.insert(0, '/mnt/fam/SERVER/IfixKartEcommerce')
from dotenv import load_dotenv
load_dotenv('/mnt/fam/SERVER/IfixKartEcommerce/Backend/.env')
import unittest
import asyncio
from swarm.scenarios import get_scenario
class TestScenarios(unittest.TestCase):
def test_pricing_elasticity_scenario(self):
async def _run():
scenario = get_scenario("pricing_elasticity")
res = await scenario.run({
"discount_pct": 20.0,
"current_price": 4000.0,
"cost_price": 2400.0,
"target_category": "Display Screens"
})
self.assertEqual(res.scenario_type, "pricing_elasticity")
self.assertEqual(res.summary_metrics["discount_pct"], 20.0)
self.assertIn("price_elasticity_coefficient", res.summary_metrics)
self.assertGreater(len(res.archetype_breakdown), 0)
self.assertGreater(len(res.interview_samples), 0)
self.assertEqual(len(res.agent_logs), 50)
self.assertIn("EPISTEMIC NOTICE", res.report_markdown)
asyncio.run(_run())
def test_whatsapp_preflight_scenario(self):
async def _run():
scenario = get_scenario("whatsapp_preflight")
res = await scenario.run({
"message_template": "Get 15% off your battery replacement today!",
"offer_type": "15% Battery Discount",
"frequency_per_month": 2,
"target_segment": "All Customers"
})
self.assertEqual(res.scenario_type, "whatsapp_preflight")
self.assertIn("whatsapp_block_risk_score", res.summary_metrics)
self.assertTrue(0.0 <= res.summary_metrics["whatsapp_block_risk_score"] <= 100.0)
self.assertIn("risk_verdict", res.summary_metrics)
self.assertGreater(len(res.archetype_breakdown), 0)
asyncio.run(_run())
def test_workshop_surge_scenario(self):
async def _run():
scenario = get_scenario("workshop_surge")
res = await scenario.run({
"surge_multiplier": 1.75,
"parts_delay_days": 2,
"active_technicians": 5
})
self.assertEqual(res.scenario_type, "workshop_surge")
self.assertIn("projected_tat_hours", res.summary_metrics)
self.assertIn("bottleneck_severity", res.summary_metrics)
self.assertGreater(res.summary_metrics["projected_tat_hours"], 0)
asyncio.run(_run())
def test_fleet_quote_scenario(self):
async def _run():
scenario = get_scenario("fleet_quote")
res = await scenario.run({
"device_count": 75,
"quoted_price_per_unit": 3950.0,
"warranty_months": 6,
"turnaround_days": 2
})
self.assertEqual(res.scenario_type, "fleet_quote")
self.assertEqual(res.summary_metrics["device_count"], 75)
self.assertIn("win_probability_category", res.summary_metrics)
self.assertIn("recommended_bid_adjustment", res.summary_metrics)
asyncio.run(_run())
if __name__ == "__main__":
unittest.main()