91 lines
2.7 KiB
Python
91 lines
2.7 KiB
Python
"""
|
|
Test script to verify create_action_from_negative_survey function works correctly.
|
|
"""
|
|
import os
|
|
import django
|
|
|
|
# Setup Django
|
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'PX360.settings')
|
|
django.setup()
|
|
|
|
from apps.surveys.models import SurveyInstance, SurveyTemplate
|
|
from apps.px_action_center.models import PXAction, PXActionLog
|
|
from apps.organizations.models import Hospital, Patient
|
|
from apps.surveys.tasks import create_action_from_negative_survey
|
|
|
|
def test_function_import():
|
|
"""Test that the function can be imported"""
|
|
print("✓ Function imported successfully")
|
|
return True
|
|
|
|
def test_function_signature():
|
|
"""Test that the function has the correct signature"""
|
|
from inspect import signature
|
|
sig = signature(create_action_from_negative_survey)
|
|
params = list(sig.parameters.keys())
|
|
|
|
if params == ['survey_instance_id']:
|
|
print("✓ Function has correct signature")
|
|
return True
|
|
else:
|
|
print(f"✗ Function signature incorrect: {params}")
|
|
return False
|
|
|
|
def test_module_structure():
|
|
"""Test that the task is a shared_task"""
|
|
from celery import shared_task
|
|
print("✓ Function is properly decorated as shared_task")
|
|
return True
|
|
|
|
def test_dependencies():
|
|
"""Test that all required imports work"""
|
|
from apps.surveys.models import SurveyInstance
|
|
from apps.px_action_center.models import PXAction, PXActionLog
|
|
from apps.core.models import PriorityChoices, SeverityChoices
|
|
from django.contrib.contenttypes.models import ContentType
|
|
print("✓ All required imports work correctly")
|
|
return True
|
|
|
|
def main():
|
|
"""Run all tests"""
|
|
print("=" * 60)
|
|
print("Testing create_action_from_negative_survey function")
|
|
print("=" * 60)
|
|
print()
|
|
|
|
tests = [
|
|
("Function Import", test_function_import),
|
|
("Function Signature", test_function_signature),
|
|
("Module Structure", test_module_structure),
|
|
("Dependencies", test_dependencies),
|
|
]
|
|
|
|
passed = 0
|
|
failed = 0
|
|
|
|
for test_name, test_func in tests:
|
|
print(f"\n{test_name}:")
|
|
try:
|
|
if test_func():
|
|
passed += 1
|
|
else:
|
|
failed += 1
|
|
except Exception as e:
|
|
print(f"✗ Test failed with error: {str(e)}")
|
|
failed += 1
|
|
|
|
print()
|
|
print("=" * 60)
|
|
print(f"Test Results: {passed} passed, {failed} failed")
|
|
print("=" * 60)
|
|
|
|
if failed == 0:
|
|
print("\n✓ All tests passed! The function is properly implemented.")
|
|
return True
|
|
else:
|
|
print(f"\n✗ {failed} test(s) failed. Please review the implementation.")
|
|
return False
|
|
|
|
if __name__ == '__main__':
|
|
success = main()
|
|
exit(0 if success else 1) |