Corp/backend/test_refactored_notifications.py
Игорь Надеин bb85f96b4b refactor: Refactor notifications module with base processors
- Created BaseNotificationProcessor with common notification logic
- Added specialized processors: Message, Event, Post, Request, Document
- Reduced tasks.py from 819 to 380 lines (53% reduction)
- Each task now 4-20 lines instead of 100-150
- Eliminated code duplication across 5 notification types
- Improved maintainability and testability
- Added test script and documentation
2026-01-09 16:56:24 +03:00

56 lines
2.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
Тест рефакторенных уведомлений
"""
import os
import django
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'eusrr_backend.settings')
django.setup()
try:
# Импорты задач
from notifications.tasks import (
process_message_notifications_task,
process_event_notifications_task,
process_post_notifications_task,
process_request_notifications_task,
process_document_notifications_task,
)
# Импорты процессоров
from notifications.task_base import (
BaseNotificationProcessor,
MessageNotificationProcessor,
EventNotificationProcessor,
PostNotificationProcessor,
RequestNotificationProcessor,
DocumentNotificationProcessor,
truncate_text,
)
print("✅ Все импорты успешны!")
print(f"✅ process_message_notifications_task: {process_message_notifications_task}")
print(f"✅ process_event_notifications_task: {process_event_notifications_task}")
print(f"✅ process_post_notifications_task: {process_post_notifications_task}")
print(f"✅ process_request_notifications_task: {process_request_notifications_task}")
print(f"✅ process_document_notifications_task: {process_document_notifications_task}")
print(f"✅ BaseNotificationProcessor: {BaseNotificationProcessor}")
print(f"✅ MessageNotificationProcessor: {MessageNotificationProcessor}")
print(f"✅ EventNotificationProcessor: {EventNotificationProcessor}")
print(f"✅ PostNotificationProcessor: {PostNotificationProcessor}")
print(f"✅ RequestNotificationProcessor: {RequestNotificationProcessor}")
print(f"✅ DocumentNotificationProcessor: {DocumentNotificationProcessor}")
print(f"✅ truncate_text: {truncate_text}")
# Тест функции truncate_text
assert truncate_text("Short text", 100) == "Short text"
assert truncate_text("Very long text that should be truncated", 10) == "Very long..."
print("✅ truncate_text работает корректно")
print("\n🎉 Рефакторинг завершён успешно!")
except Exception as e:
print(f"❌ Ошибка: {e}")
import traceback
traceback.print_exc()