HH/test_complaint_form_fix.py

50 lines
1.8 KiB
Python

#!/usr/bin/env python
"""
Test script to verify the complaint form fix.
Tests that forms can be imported and instantiated without errors.
"""
def test_form_import():
"""Test that forms can be imported without TypeError"""
print("Testing complaint form fix...")
print("-" * 50)
try:
# Import forms - this should not raise TypeError anymore
from apps.complaints.forms import PublicComplaintForm, ComplaintForm
print("✓ Forms imported successfully (no TypeError)")
# Check that the forms have the expected fields
print(f"\nPublicComplaintForm has {len(PublicComplaintForm.base_fields)} fields")
print(f"ComplaintForm has {len(ComplaintForm.base_fields)} fields")
# Check for complaint_source_type field
if 'complaint_source_type' in PublicComplaintForm.base_fields:
print("✓ complaint_source_type field found in PublicComplaintForm")
else:
print("✗ complaint_source_type field NOT found in PublicComplaintForm")
if 'complaint_source_type' in ComplaintForm.base_fields:
print("✓ complaint_source_type field found in ComplaintForm")
else:
print("✗ complaint_source_type field NOT found in ComplaintForm")
print("\n" + "=" * 50)
print("SUCCESS: All tests passed!")
print("=" * 50)
return True
except TypeError as e:
print(f"\n✗ FAILED: TypeError occurred: {e}")
print("The fix did not work properly.")
return False
except Exception as e:
print(f"\n✗ FAILED: Unexpected error: {e}")
return False
if __name__ == '__main__':
import sys
success = test_form_import()
sys.exit(0 if success else 1)