201 lines
6.5 KiB
Python
201 lines
6.5 KiB
Python
"""
|
|
Verify SMS notification implementation for complaints
|
|
|
|
This script verifies that the SMS notification feature has been properly implemented
|
|
by checking the code structure and key components.
|
|
"""
|
|
import os
|
|
import sys
|
|
|
|
def check_file_exists(filepath, description):
|
|
"""Check if a file exists and report"""
|
|
if os.path.exists(filepath):
|
|
print(f"✓ {description}: {filepath}")
|
|
return True
|
|
else:
|
|
print(f"✗ {description} NOT FOUND: {filepath}")
|
|
return False
|
|
|
|
def check_file_contains(filepath, content, description):
|
|
"""Check if a file contains specific content"""
|
|
try:
|
|
with open(filepath, 'r') as f:
|
|
file_content = f.read()
|
|
if content in file_content:
|
|
print(f" ✓ {description}")
|
|
return True
|
|
else:
|
|
print(f" ✗ {description} NOT FOUND")
|
|
return False
|
|
except FileNotFoundError:
|
|
print(f" ✗ File not found: {filepath}")
|
|
return False
|
|
|
|
def verify_implementation():
|
|
"""Verify the SMS notification implementation"""
|
|
print("=" * 70)
|
|
print("Verifying Complaint SMS Notification Implementation")
|
|
print("=" * 70)
|
|
print()
|
|
|
|
all_checks_passed = True
|
|
|
|
# Check 1: signals.py file exists
|
|
print("1. Checking signals.py file...")
|
|
if check_file_exists('apps/complaints/signals.py', 'Signal handlers file'):
|
|
# Check for key signal handlers
|
|
check_file_contains(
|
|
'apps/complaints/signals.py',
|
|
'def send_complaint_creation_sms',
|
|
' Creation SMS handler'
|
|
)
|
|
check_file_contains(
|
|
'apps/complaints/signals.py',
|
|
'def send_complaint_status_change_sms',
|
|
' Status change SMS handler'
|
|
)
|
|
check_file_contains(
|
|
'apps/complaints/signals.py',
|
|
'NotificationService.send_sms',
|
|
' NotificationService integration'
|
|
)
|
|
check_file_contains(
|
|
'apps/complaints/signals.py',
|
|
"tracking_url': instance.get_tracking_url()",
|
|
' Tracking URL in SMS'
|
|
)
|
|
else:
|
|
all_checks_passed = False
|
|
print()
|
|
|
|
# Check 2: apps.py connects signals
|
|
print("2. Checking apps.py signal connection...")
|
|
if check_file_exists('apps/complaints/apps.py', 'Apps configuration'):
|
|
check_file_contains(
|
|
'apps/complaints/apps.py',
|
|
'import apps.complaints.signals',
|
|
' Signals imported in ready()'
|
|
)
|
|
else:
|
|
all_checks_passed = False
|
|
print()
|
|
|
|
# Check 3: models.py has get_tracking_url() method
|
|
print("3. Checking models.py tracking URL method...")
|
|
if check_file_exists('apps/complaints/models.py', 'Complaint models'):
|
|
check_file_contains(
|
|
'apps/complaints/models.py',
|
|
'def get_tracking_url(self):',
|
|
' get_tracking_url() method'
|
|
)
|
|
check_file_contains(
|
|
'apps/complaints/models.py',
|
|
'self._status_was = old_instance.status',
|
|
' Status tracking in save()'
|
|
)
|
|
else:
|
|
all_checks_passed = False
|
|
print()
|
|
|
|
# Check 4: Check SMS messages are bilingual
|
|
print("4. Checking bilingual SMS messages...")
|
|
if check_file_exists('apps/complaints/signals.py', 'Signal handlers'):
|
|
check_file_contains(
|
|
'apps/complaints/signals.py',
|
|
"'en':",
|
|
' English SMS messages'
|
|
)
|
|
check_file_contains(
|
|
'apps/complaints/signals.py',
|
|
"'ar':",
|
|
' Arabic SMS messages'
|
|
)
|
|
check_file_contains(
|
|
'apps/complaints/signals.py',
|
|
"'resolved':",
|
|
' Resolved status message'
|
|
)
|
|
check_file_contains(
|
|
'apps/complaints/signals.py',
|
|
"'closed':",
|
|
' Closed status message'
|
|
)
|
|
else:
|
|
all_checks_passed = False
|
|
print()
|
|
|
|
# Check 5: Check error handling
|
|
print("5. Checking error handling...")
|
|
if check_file_exists('apps/complaints/signals.py', 'Signal handlers'):
|
|
check_file_contains(
|
|
'apps/complaints/signals.py',
|
|
'except Exception as e:',
|
|
' Exception handling'
|
|
)
|
|
check_file_contains(
|
|
'apps/complaints/signals.py',
|
|
'logger.error',
|
|
' Error logging'
|
|
)
|
|
else:
|
|
all_checks_passed = False
|
|
print()
|
|
|
|
# Check 6: Check ComplaintUpdate tracking
|
|
print("6. Checking ComplaintUpdate tracking...")
|
|
if check_file_exists('apps/complaints/signals.py', 'Signal handlers'):
|
|
check_file_contains(
|
|
'apps/complaints/signals.py',
|
|
"ComplaintUpdate.objects.create(",
|
|
' ComplaintUpdate creation'
|
|
)
|
|
check_file_contains(
|
|
'apps/complaints/signals.py',
|
|
"update_type='communication'",
|
|
' Communication type tracking'
|
|
)
|
|
else:
|
|
all_checks_passed = False
|
|
print()
|
|
|
|
# Check 7: Check phone number validation
|
|
print("7. Checking phone number validation...")
|
|
if check_file_exists('apps/complaints/signals.py', 'Signal handlers'):
|
|
check_file_contains(
|
|
'apps/complaints/signals.py',
|
|
'if not instance.contact_phone:',
|
|
' Phone number check'
|
|
)
|
|
check_file_contains(
|
|
'apps/complaints/signals.py',
|
|
'Skipping SMS',
|
|
' Skip SMS when no phone'
|
|
)
|
|
else:
|
|
all_checks_passed = False
|
|
print()
|
|
|
|
# Summary
|
|
print("=" * 70)
|
|
if all_checks_passed:
|
|
print("✓ SMS Notification Implementation: VERIFIED")
|
|
print()
|
|
print("Summary of Implementation:")
|
|
print("- Automatic SMS on complaint creation (with tracking URL)")
|
|
print("- Automatic SMS on status change to resolved")
|
|
print("- Automatic SMS on status change to closed")
|
|
print("- Bilingual SMS messages (English/Arabic)")
|
|
print("- Phone number validation (no SMS if no phone provided)")
|
|
print("- Error handling (SMS failures don't break complaint save)")
|
|
print("- ComplaintUpdate tracking for all SMS notifications")
|
|
print("- Status change detection (only sends on actual status changes)")
|
|
print("=" * 70)
|
|
return 0
|
|
else:
|
|
print("✗ SMS Notification Implementation: INCOMPLETE")
|
|
print("=" * 70)
|
|
return 1
|
|
|
|
if __name__ == '__main__':
|
|
exit_code = verify_implementation()
|
|
sys.exit(exit_code) |