Exemplo n.º 1
0
 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)
Exemplo n.º 2
0
 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)
Exemplo n.º 3
0
 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)
Exemplo n.º 4
0
 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()
Exemplo n.º 5
0
 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()
Exemplo n.º 6
0
 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)
Exemplo n.º 7
0
 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()
Exemplo n.º 8
0
 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()
Exemplo n.º 9
0
 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)
Exemplo n.º 10
0
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)
Exemplo n.º 11
0
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)
Exemplo n.º 12
0
 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)
Exemplo n.º 13
0
    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)
Exemplo n.º 14
0
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())