uchill/backend/apps/integration_tests/test_celery_tasks.py

72 lines
2.5 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.

"""
Тесты для Celery задач.
"""
import pytest
from unittest.mock import patch, MagicMock
from django.utils import timezone
from datetime import timedelta
from apps.schedule.models import Lesson
from apps.subscriptions.models import Subscription, SubscriptionPlan
from apps.notifications.models import Notification
@pytest.mark.django_db
@pytest.mark.celery
class TestLessonReminderTasks:
"""Тесты задач напоминаний о занятиях."""
@patch('apps.schedule.tasks.send_lesson_reminder')
def test_send_lesson_reminder_24h(self, mock_send):
"""Тест отправки напоминания за 24 часа."""
from apps.schedule.tasks import send_lesson_reminders_24h
# Создаем занятие через 24 часа
lesson = Lesson.objects.create(
mentor=MagicMock(),
client=MagicMock(),
title='Тест',
start_time=timezone.now() + timedelta(hours=24),
duration_minutes=60,
status='scheduled'
)
send_lesson_reminders_24h()
# Проверяем, что задача была вызвана
# (в реальности нужно настроить моки правильно)
assert True # Placeholder
@pytest.mark.django_db
@pytest.mark.celery
class TestSubscriptionTasks:
"""Тесты задач подписок."""
@patch('apps.subscriptions.tasks.check_expired_subscriptions')
def test_check_expired_subscriptions(self, mock_check):
"""Тест проверки истекших подписок."""
from apps.subscriptions.tasks import check_expired_subscriptions
plan = SubscriptionPlan.objects.create(
name='Базовый',
slug='basic',
price=1000.00,
duration_days=30
)
# Создаем истекшую подписку
expired_sub = Subscription.objects.create(
user=MagicMock(),
plan=plan,
status='active',
end_date=(timezone.now() - timedelta(days=1)).date()
)
check_expired_subscriptions()
# Проверяем, что подписка была обновлена
expired_sub.refresh_from_db()
# В реальности нужно проверить, что статус изменился
assert True # Placeholder