174 lines
6.3 KiB
Python
174 lines
6.3 KiB
Python
#!/usr/bin/env python
|
|
"""
|
|
Test script to verify the "Partially Resolved" status implementation
|
|
"""
|
|
|
|
import os
|
|
import django
|
|
|
|
# Setup Django
|
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'PX360.settings')
|
|
django.setup()
|
|
|
|
from django.test import TestCase, Client
|
|
from django.urls import reverse
|
|
from apps.complaints.models import Complaint
|
|
from apps.accounts.models import User
|
|
from apps.organizations.models import Hospital, Department, Staff
|
|
|
|
class PartiallyResolvedStatusTest(TestCase):
|
|
"""Test the partially resolved status functionality"""
|
|
|
|
def setUp(self):
|
|
"""Create test data"""
|
|
# Create hospital and department
|
|
self.hospital = Hospital.objects.create(
|
|
name="Test Hospital",
|
|
name_ar="مستشفى تجريبي",
|
|
code="TEST001"
|
|
)
|
|
|
|
self.department = Department.objects.create(
|
|
hospital=self.hospital,
|
|
name="Test Department",
|
|
name_ar="قسم تجريبي",
|
|
code="DEPT001"
|
|
)
|
|
|
|
# Create admin user
|
|
self.admin_user = User.objects.create_user(
|
|
email='admin@test.com',
|
|
password='testpass123',
|
|
first_name='Admin',
|
|
last_name='User',
|
|
is_px_admin=True
|
|
)
|
|
|
|
# Create staff member
|
|
self.staff = Staff.objects.create(
|
|
hospital=self.hospital,
|
|
department=self.department,
|
|
first_name_en='Test',
|
|
last_name_en='Staff',
|
|
first_name_ar='تجريبي',
|
|
last_name_ar='موظف',
|
|
email='staff@test.com',
|
|
job_title='Nurse'
|
|
)
|
|
|
|
# Create a complaint
|
|
self.complaint = Complaint.objects.create(
|
|
reference_number='CMP-TEST-001',
|
|
hospital=self.hospital,
|
|
department=self.department,
|
|
complaint_type='complaint',
|
|
status='open',
|
|
title='Test Complaint',
|
|
description='This is a test complaint'
|
|
)
|
|
|
|
self.client = Client()
|
|
|
|
def test_status_choices_includes_partially_resolved(self):
|
|
"""Test that partially_resolved is in status choices"""
|
|
status_choices = [choice[0] for choice in Complaint.STATUS_CHOICES]
|
|
self.assertIn('partially_resolved', status_choices)
|
|
|
|
def test_complaint_can_be_partially_resolved(self):
|
|
"""Test that a complaint can be set to partially_resolved"""
|
|
self.complaint.status = 'partially_resolved'
|
|
self.complaint.save()
|
|
|
|
# Reload from database
|
|
reloaded_complaint = Complaint.objects.get(pk=self.complaint.pk)
|
|
self.assertEqual(reloaded_complaint.status, 'partially_resolved')
|
|
|
|
def test_partially_resolved_display_label(self):
|
|
"""Test the display label for partially resolved"""
|
|
self.complaint.status = 'partially_resolved'
|
|
self.assertEqual(
|
|
self.complaint.get_status_display(),
|
|
'Partially Resolved'
|
|
)
|
|
|
|
def test_partially_resolved_status_workflow(self):
|
|
"""Test workflow from open -> in_progress -> partially_resolved -> resolved"""
|
|
# Open -> In Progress
|
|
self.complaint.status = 'in_progress'
|
|
self.complaint.assigned_to = self.admin_user
|
|
self.complaint.assigned_at = django.utils.timezone.now()
|
|
self.complaint.save()
|
|
self.assertEqual(self.complaint.status, 'in_progress')
|
|
|
|
# In Progress -> Partially Resolved
|
|
self.complaint.status = 'partially_resolved'
|
|
self.complaint.resolution = 'Partial resolution: Initial compensation provided'
|
|
self.complaint.resolution_category = 'refund'
|
|
self.complaint.resolved_by = self.admin_user
|
|
self.complaint.resolved_at = django.utils.timezone.now()
|
|
self.complaint.save()
|
|
self.assertEqual(self.complaint.status, 'partially_resolved')
|
|
self.assertIsNotNone(self.complaint.resolution)
|
|
|
|
# Partially Resolved -> Fully Resolved
|
|
self.complaint.status = 'resolved'
|
|
self.complaint.resolution = 'Full resolution: Complete refund and apology'
|
|
self.complaint.resolved_at = django.utils.timezone.now()
|
|
self.complaint.save()
|
|
self.assertEqual(self.complaint.status, 'resolved')
|
|
|
|
def test_public_tracking_page_shows_partially_resolved(self):
|
|
"""Test that public tracking page shows partially_resolved status correctly"""
|
|
self.complaint.status = 'partially_resolved'
|
|
self.complaint.resolution = 'Partial resolution applied'
|
|
self.complaint.resolution_category = 'service_improvement'
|
|
self.complaint.resolved_by = self.admin_user
|
|
self.complaint.resolved_at = django.utils.timezone.now()
|
|
self.complaint.save()
|
|
|
|
# Access the tracking page
|
|
response = self.client.post(
|
|
reverse('complaints:public_track'),
|
|
{'reference_number': self.complaint.reference_number}
|
|
)
|
|
|
|
self.assertEqual(response.status_code, 200)
|
|
self.assertContains(response, 'Partially Resolved')
|
|
self.assertContains(response, 'status-partially_resolved')
|
|
|
|
def test_css_classes_present(self):
|
|
"""Test that CSS classes for partially_resolved are present in templates"""
|
|
# Check complaint detail template
|
|
response = self.client.get(reverse('complaints:complaint_detail', args=[self.complaint.pk]))
|
|
self.assertEqual(response.status_code, 200)
|
|
# The template should have the CSS class defined
|
|
self.assertContains(response, 'status-partially_resolved')
|
|
|
|
|
|
def run_tests():
|
|
"""Run all tests"""
|
|
import unittest
|
|
|
|
# Create test suite
|
|
suite = unittest.TestLoader().loadTestsFromTestCase(PartiallyResolvedStatusTest)
|
|
|
|
# Run tests
|
|
runner = unittest.TextTestRunner(verbosity=2)
|
|
result = runner.run(suite)
|
|
|
|
# Print summary
|
|
print("\n" + "="*70)
|
|
print("TEST SUMMARY")
|
|
print("="*70)
|
|
print(f"Tests run: {result.testsRun}")
|
|
print(f"Successes: {result.testsRun - len(result.failures) - len(result.errors)}")
|
|
print(f"Failures: {len(result.failures)}")
|
|
print(f"Errors: {len(result.errors)}")
|
|
print("="*70)
|
|
|
|
return result.wasSuccessful()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
success = run_tests()
|
|
exit(0 if success else 1) |