def test_get_description_for_comment_like(self): notification = Notification(sender=self.sender, receiver=self.receiver, comment=self.comment, notif_type=Notification.COMMENT_LIKED, created=timezone.now()) response_string = notification.get_description() self.assertIn('liked your comment', response_string)
def test_get_description_for_thread_create(self): notification = Notification(sender=self.sender, receiver=self.receiver, thread=self.thread, notif_type=Notification.THREAD_CREATED, created=timezone.now()) response_string = notification.get_description() self.assertIn('started a new thread', response_string)
def test_get_description_for_thread_update(self): notification = Notification(sender=self.sender, receiver=self.receiver, thread=self.thread, notif_type=Notification.THREAD_UPDATED, created=timezone.now()) response_string = notification.get_description() self.assertIn('updated a thread you are following', response_string)
def test_save_using_comment_and_invalid_notif_type(self): notification = Notification(sender=self.sender, receiver=self.receiver, comment=self.comment, notif_type=Notification.THREAD_CREATED) msg = 'Invalid notification type for field comment' with self.assertRaisesMessage(FieldError, msg): notification.save()
def test_save_using_invalid_notif_type(self): notification = Notification(sender=self.sender, receiver=self.receiver, comment=self.comment, notif_type='invalid notif type') msg = 'Invalid notification type' with self.assertRaisesMessage(FieldError, msg): notification.save()
def test_get_description_for_user_mentioned(self): notification = Notification(sender=self.sender, receiver=self.receiver, comment=self.comment, notif_type=Notification.USER_MENTIONED, created=timezone.now()) response_string = notification.get_description() self.assertIn('mentioned you in a comment', response_string)
def test_save_using_thread_and_invalid_notif_type(self): notification = Notification(sender=self.sender, receiver=self.receiver, thread=self.thread, notif_type=Notification.COMMENT_LIKED) msg = 'Invalid notification type for field thread' with self.assertRaisesMessage(FieldError, msg): notification.save()
def test_save_using_thread_and_comment(self): notification = Notification(sender=self.sender, receiver=self.receiver, thread=self.thread, comment=self.comment, notif_type=Notification.THREAD_CREATED) msg = 'Notification cannot have both comment field and thread field set.' with self.assertRaisesMessage(FieldError, msg): notification.save()
def test_get_precise_url(self): notification = Notification(sender=self.sender, receiver=self.receiver, comment=self.comment, notif_type=Notification.USER_MENTIONED, created=timezone.now()) expected_url = '%s?page=%s' % (reverse( 'accounts:user_notifs', kwargs={'username': self.receiver.username}), 3) self.assertEqual(notification.get_precise_url(9), expected_url)
def _perform_comment_post_save_actions(comment, prev_msg, mentions): comment.mentioned_users.add(*mentions) Attachment.objects.synchronise(comment, prev_msg) user_list = get_user_list_without_creator(mentions, comment.user) notif = Notification(sender=comment.user, comment=comment, notif_type=Notification.USER_MENTIONED) Notification.objects.notify_users(notif, user_list)
def perform_thread_post_update_actions(thread): followers = get_user_list_without_creator(thread.followers.all(), thread.user) notif = Notification(sender=thread.user, thread=thread, notif_type=Notification.THREAD_UPDATED) Notification.objects.notify_users(notif, followers)
def test_notify_mentioned_users(self): notif = Notification(sender=self.comment.user, comment=self.comment, notif_type=Notification.USER_MENTIONED) Notification.objects.notify_users(notif, self.receiver_list) notifs = Notification.objects.all() self.assertEqual(notifs[0].receiver, self.receiver) self.assertEqual(notifs[1].receiver, self.receiver2) notif_qs = Notification.objects.filter( notif_type=Notification.USER_MENTIONED) self.assertTrue(notif_qs.count(), 2)
def test_notify_thread_followers_for_modification(self): user = self.make_user('testuser4') self.sender.followers.add(user) for receiver in self.receiver_list: ThreadFollowership.objects.create(user=receiver, thread=self.thread) notif = Notification(sender=self.thread.user, thread=self.thread, notif_type=Notification.THREAD_UPDATED) Notification.objects.notify_users(notif, self.thread.followers.all()) notifs = Notification.objects.all() self.assertEqual(notifs[0].receiver, self.receiver) self.assertEqual(notifs[1].receiver, self.receiver2) self.assertNotIn(user, notifs) self.assertNotIn(self.sender, notifs) notif_qs = Notification.objects.filter( notif_type=Notification.THREAD_UPDATED) self.assertTrue(notif_qs.count(), 2)
def perform_thread_post_create_actions(thread): ThreadFollowership.objects.get_or_create(user=thread.user, thread=thread) notif = Notification(sender=thread.user, thread=thread, notif_type=Notification.THREAD_CREATED) Notification.objects.notify_users(notif, thread.user.followers.all())