# SLA Testing Quick Start Get started with realistic SLA testing in 5 minutes! ## Quick Setup ### 1. Verify Your Environment ```bash # Check Django is configured cat .env | grep DJANGO_SETTINGS_MODULE # Should show: DJANGO_SETTINGS_MODULE=config.settings.dev ``` ### 2. Run Scenario 1 (Happy Path - ~7 seconds) ```bash python test_scenario_1_successful_explanation.py ``` **What it tests**: Staff submits explanation before deadline ✅ **Expected output**: ``` TEST SUMMARY Total Steps: 7 Successful: 7 Failed: 0 Elapsed Time: 7.2s ✓✓✓ ALL TESTS PASSED ✓✓✓ ``` ### 3. Run Scenario 2 (Escalation - ~37 seconds) ```bash python test_scenario_2_escalation_with_reminders.py ``` **What it tests**: - Staff doesn't respond ⚠️ - First reminder sent ⚠️ - Second reminder sent ⚠️ - Escalates to manager 📈 - Escalates to department head 📈 **Expected output**: ``` TEST SUMMARY Total Steps: 12 Successful: 12 Failed: 0 Elapsed Time: 37.5s ✓✓✓ ALL TESTS PASSED ✓✓✓ ``` ## What Just Happened? ### Time Compression Magic The tests use **1 second = 1 hour** time compression: - Real SLA: 48 hours → Test time: 48 seconds - Real SLA: 12 hours → Test time: 12 seconds This means you can test a **full 2-day workflow in under 1 minute!** ### Real System Execution These are **NOT mocks** - they execute real code: ✅ Real database operations ✅ Real Celery tasks ✅ Real email sending ✅ Real SLA calculations ✅ Real escalation logic ## What Gets Created ### Scenario 1 Creates: - 1 Hospital (Al Hammadi Hospital) - 1 Department (Emergency Department) - 1 Staff member (Omar Al-Harbi - Nurse) - 1 Complaint (Poor response time) - 1 Explanation request (submitted) - 1 ExplanationSLAConfig (10-hour deadline) - 1 ComplaintSLAConfig (72-hour SLA) ### Scenario 2 Creates: - 1 Hospital (Al Hammadi Hospital) - 1 Department (Emergency Department) - 3 Staff members (Staff → Manager → Department Head) - 1 Complaint (High severity, high priority) - 1 Explanation request (overdue, escalated) - 1 ExplanationSLAConfig (12-hour deadline with reminders) - 1 SecondReminderConfig (3 hours before deadline) - 1 ComplaintSLAConfig (48-hour SLA) ## Verify Results in Django Admin ```bash # Start Django server python manage.py runserver # Visit: http://localhost:8000/admin # Login with your admin credentials # Check: # - Complaints → All Complaints # - Complaints → Explanations # - Organizations → Staff # - Complaints → SLA Configurations ``` ## Clean Up Test Data ```bash python manage.py shell ``` ```python # Delete test complaints from apps.complaints.models import Complaint, ComplaintExplanation Complaint.objects.filter(contact_name="Test Patient").delete() Complaint.objects.filter(contact_name="Concerned Family Member").delete() # Delete test staff (be careful!) from apps.organizations.models import Staff Staff.objects.filter(email__contains=".test").delete() # Delete test SLA configs from apps.complaints.models import ExplanationSLAConfig, ComplaintSLAConfig, SecondReminderConfig ExplanationSLAConfig.objects.all().delete() ComplaintSLAConfig.objects.all().delete() SecondReminderConfig.objects.all().delete() ``` ## Common Issues ### Issue: "Database error" **Solution**: ```bash python manage.py migrate ``` ### Issue: "Email failed to send" **Solution**: Add to `.env`: ``` EMAIL_BACKEND=django.core.mail.backends.console.EmailBackend ``` ### Issue: "Module not found" **Solution**: Make sure you're in the project root: ```bash cd /home/ismail/projects/HH ``` ## Customize Your Test ### Change Time Compression Edit the test script: ```python # Make it faster (1s = 2h) test = Scenario1SuccessfulExplanation(time_compression_ratio=2) # Make it slower (1s = 30min) test = Scenario1SuccessfulExplanation(time_compression_ratio=0.5) ``` ### Change SLA Deadline Edit the SLA config in the test: ```python self.create_explanation_sla_config( hospital=hospital, response_hours=24, # Change from 10 to 24 hours reminder_hours_before=12, # Change from 5 to 12 hours auto_escalate_enabled=True, escalation_hours_overdue=0, max_escalation_levels=3 ) ``` ## Next Steps 1. ✅ Run both scenarios successfully 2. ✅ Review results in Django admin 3. ✅ Check the email output (console or real email) 4. ✅ Customize SLA settings to match your needs 5. ✅ Read the full guide: `docs/REAL_TIME_SLA_TESTING_GUIDE.md` ## Need Help? - Full documentation: `docs/REAL_TIME_SLA_TESTING_GUIDE.md` - SLA system overview: `docs/SLA_SYSTEM_OVERVIEW.md` - Celery tasks: `apps/complaints/tasks.py` - Models: `apps/complaints/models.py` --- **Ready to test? Run Scenario 1 now:** ```bash python test_scenario_1_successful_explanation.py