fix(notification): fixed formatting and linting

This commit is contained in:
sankalp committed 2025-12-11 21:09:14 +05:45
1 parent 466d4b868a
commit 63d63d5e5c
7 files changed
+57 -57

No files matched your search

+18 -24
View File
@@ -1,56 +1,50 @@
from django.contrib.auth import get_user_model
from django.core import mail
from django.test import TestCase
from django.utils import timezone
from django.core import mail
from django.contrib.auth import get_user_model
from src.models.projects import Project
from src.models.clients import Client
from src.models.notifications import check_and_send_notifications, Notification
from src.models.notifications import Notification, check_and_send_notifications
from src.models.projects import Project
User = get_user_model()
class NotificationTests(TestCase):
def test_send_deadline_notifications(self):
# Setup
admin = User.objects.create_superuser('admin', 'admin@example.com', 'password')
User.objects.create_superuser("admin", "admin@example.com", "password")
client = Client.objects.create(name="Test Client", email="client@example.com")
# Project due tomorrow
tomorrow = timezone.localdate() + timezone.timedelta(days=1)
project = Project.objects.create(
name="Test Project",
client=client,
deadline=tomorrow
)
Project.objects.create(name="Test Project", client=client, deadline=tomorrow)
# Run notification check
check_and_send_notifications()
# Verify emails sent
# Expecting 2 emails: 1 to client, 1 to admin
self.assertEqual(len(mail.outbox), 2)
# Verify Notification objects created
self.assertEqual(Notification.objects.count(), 2)
client_notif = Notification.objects.get(recipient="client@example.com")
self.assertIn("Project Deadline Reminder", client_notif.subject)
admin_notif = Notification.objects.get(recipient="admin@example.com")
self.assertIn("Admin Alert", admin_notif.subject)
def test_no_notifications_if_not_due(self):
# Setup
client = Client.objects.create(name="Test Client", email="client@example.com")
# Project due day after tomorrow
day_after = timezone.localdate() + timezone.timedelta(days=2)
Project.objects.create(
name="Future Project",
client=client,
deadline=day_after
)
Project.objects.create(name="Future Project", client=client, deadline=day_after)
check_and_send_notifications()
self.assertEqual(len(mail.outbox), 0)
self.assertEqual(Notification.objects.count(), 0)