Corp/backend/tests/manual/test_announcement_notifications.py
Игорь Надеин 0663fe02b0 refactor: реорганизация тестов для улучшения структуры и производительности
- Перемещены manual tests из scripts/manual_tests в tests/manual/
- Обновлен pytest.ini с правильными маркерами и конфигурацией
- Добавлен tests/manual/conftest.py для автоматической пометки manual тестов
- Исключены manual tests из автоматических запусков
- Удалены конфликтующие тестовые файлы

Результаты:
- Провалы: 113 → 94 (-19, -17%)
- Ошибки: 12 → 3 (-9, -75%)
- Успешность: 65% → 70% (+5%)
- Скорость: 20.71s → 16.46s (+20% быстрее)

Все изменения не влияют на основной код, только на структуру тестов.
2026-01-05 07:41:34 +03:00

85 lines
3.4 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.

#!/usr/bin/env python
"""
Тестирование уведомлений для объявлений
"""
import os
import django
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'eusrr_backend.settings')
django.setup()
from communications.models import Chat, Message
from employees.models import Employee
def test_announcement_notifications():
"""Проверяет, что уведомления для объявлений отправляются всем"""
# Находим чат-объявление
announcement = Chat.objects.filter(type='announcement').first()
if not announcement:
print("❌ Нет объявлений в системе")
return
print(f"✓ Найдено объявление: {announcement.name}")
print(f" Created by: {announcement.created_by}")
print(f" include_all_employees: {announcement.include_all_employees}")
# Получаем участников
participants = announcement.get_participants
print(f" Участников (get_participants): {participants.count()}")
# Список участников
for p in participants[:5]:
print(f" - {p.get_full_name() or p.username} ({p.email})")
if participants.count() > 5:
print(f" ... и ещё {participants.count() - 5}")
# Проверяем последнее сообщение
last_message = announcement.messages.order_by('-created_at').first()
if last_message:
print(f"\n✓ Последнее сообщение:")
print(f" ID: {last_message.id}")
print(f" Автор: {last_message.author}")
print(f" Текст: {last_message.content[:50]}...")
print(f" Создано: {last_message.created_at}")
# Проверяем уведомления
from notifications.models import Notification
notifications = Notification.objects.filter(
content_type__model='message',
object_id=last_message.id
)
print(f"\n✓ Уведомлений создано: {notifications.count()}")
# Проверяем тип уведомлений
announcement_notifs = notifications.filter(
notification_type__code='announcement_new_message'
)
print(f" Типа 'announcement_new_message': {announcement_notifs.count()}")
# Показываем первые 5
for n in notifications[:5]:
print(f" - Для: {n.recipient.get_full_name()}")
print(f" Тип: {n.notification_type.code}")
print(f" Прочитано: {n.is_read}")
else:
print("\n❌ Нет сообщений в объявлении")
# Итоги
print("\n" + "="*60)
all_employees = Employee.objects.filter(is_active=True).count()
print(f"Всего активных сотрудников: {all_employees}")
print(f"Участников объявления: {participants.count()}")
if participants.count() == all_employees:
print("✅ ПРАВИЛЬНО: Все сотрудники получат уведомления")
else:
print(f"⚠️ ВНИМАНИЕ: Уведомления получат только {participants.count()} из {all_employees}")
if __name__ == '__main__':
test_announcement_notifications()