Source code for tests.notifications.test_service

from unittest import TestCase

from apps.notifications.constants import NotificationTypeChoices
from apps.notifications.models import Notification
from services.notifications.notification import NotificationService
from tests.posts.factories import PostFactory
from tests.users.factories import UserFactory  # type: ignore


[docs] class TestNotificationService(TestCase): """Test notification service"""
[docs] def setUp(self) -> None: self.user = UserFactory() self.service = NotificationService self.post = PostFactory(author=self.user)
[docs] def test_create_notification_with_same_sender_and_recever(self): self.service.create( sender=self.user, receiver=self.user, post=self.post, data={}, type=NotificationTypeChoices.LIKE ) self.assertFalse(Notification.objects.filter(sender=self.user, receiver=self.user, post=self.post).exists())
[docs] def test_create_notification(self): self.another_user = UserFactory() self.service.create( sender=self.another_user, receiver=self.user, post=self.post, data={}, type=NotificationTypeChoices.LIKE ) self.assertTrue( Notification.objects.filter(sender=self.another_user, receiver=self.user, post=self.post).exists() )