Пример #1
0
    def test_expander_honors_unsubscribe_per_channel(self):
        author = utils.create_user()
        comment = utils.create_comment()
        comment.author = author
        comment.save()

        self.assertEqual(comment.thread.op.author, author)

        another_user = utils.create_user()

        pn = Actions.replied(another_user, comment)

        notifications = expander.expand(pn)
        self.assertTrue(notifications)

        notification = filter(lambda n: n.channel == 'EmailChannel',
                              notifications)[0]
        self.assertEqual(author, notification.recipient)

        # Now, let the user unsubscribe to the reply action.
        author.kv.subscriptions.unsubscribe('thread_replied')
        pn = Actions.replied(another_user, comment)
        notifications = expander.expand(pn)
        recipients = [
            n.recipient for n in notifications if n.channel == 'EmailChannel'
        ]
        self.assertFalse(author in recipients)
Пример #2
0
    def test_replied_tells_author_and_op_author(self):
        # Some dude starts a thread
        author = create_user()
        content = create_content()
        op = create_comment(author=author, reply_content=content)

        # Another dude posts a reply
        guest_author = create_user()
        reply = create_comment(replied_comment=op, author=guest_author, parent_comment=op)
        
        self.assertEqual(reply.thread.op, op)

        # A third dude replies to the guest author
        guest_author_2 = create_user()
        reply_2 = create_comment(replied_comment=reply, author=guest_author_2, parent_comment=op)

        self.assertTrue(reply_2.thread.op.author, author)

        # Issue the action
        pn = Actions.replied(guest_author_2, reply_2)

        notifications = expander.expand(pn)
        print notifications
        # Now, we should tell both the OP author, and the guest author.
        notifications = filter(lambda n: n.channel == 'EmailChannel', notifications)
        self.assertEqual(len(notifications), 2)
        n1 = notifications[0]
        n2 = notifications[1]

        self.assertEqual(n1.action, 'replied')
        self.assertEqual(n1.recipient, guest_author)

        self.assertEqual(n2.action, 'thread_replied')
        self.assertEqual(n2.recipient, author)
Пример #3
0
 def test_Notification_from_pn(self):
     pn = Actions.replied(create_user(), create_comment())
     notification = Notification.from_pending_notification(pn, create_user, "EmailChannel")
     assert notification.recipient
     for key in pn.data:
         self.assertEqual(getattr(notification, key), getattr(pn, key))
     assert pn.comment
     assert notification.comment
Пример #4
0
    def test_delivering_email_records_email_sent_metric(self):
        with override_service('experiment_placer', FakeExperimentPlacer, kwargs={'email_notifications': 'experimental'}):
            user = create_user(email="*****@*****.**")

            comment = create_comment()
            comment2 = create_comment(author=user, replied_comment=comment)

            pn = Actions.replied(user, comment2)
            notification = Notification.from_pending_notification(pn, user, "EmailChannel")
            channel = EmailChannel()

            with override_service('metrics', FakeMetrics):
                channel.deliver(notification)
                self.assertEqual(1, len(Services.metrics.email_sent.records))
Пример #5
0
    def test_replied_to_own_thread_does_not_email_self(self):
        user = create_user()
        comment = create_comment(author=user)

        assert comment.author == user

        reply = create_comment(replied_comment=comment)
        assert comment == reply.replied_comment

        pn = Actions.replied(user, reply)
        notifications = expander.expand(pn)

        recipients = [n.recipient for n in notifications]
        self.assertNotIn(user, recipients)
    def test_replied_to_own_thread_does_not_email_self(self):
        user = create_user()
        comment = create_comment(author=user)

        assert comment.author == user

        reply = create_comment(replied_comment=comment)
        assert comment == reply.replied_comment

        pn = Actions.replied(user, reply)
        notifications = expander.expand(pn)

        recipients = [n.recipient for n in notifications]
        self.assertNotIn(user, recipients)
    def test_delivering_email_records_email_sent_metric(self):
        with override_service('experiment_placer', FakeExperimentPlacer, kwargs={'email_notifications': 'experimental'}):
            user = create_user(email="*****@*****.**")

            comment = create_comment()
            comment2 = create_comment(author=user, replied_comment=comment)

            pn = Actions.replied(user, comment2)
            notification = Notification.from_pending_notification(pn, user, "EmailChannel")
            channel = EmailChannel()

            with override_service('metrics', FakeMetrics):
                channel.deliver(notification)
                self.assertEqual(1, len(Services.metrics.email_sent.records))
    def test_expander_honors_unsubscribe_per_channel(self):
        author = utils.create_user()
        comment = utils.create_comment()
        comment.author = author
        comment.save()
        
        self.assertEqual(comment.thread.op.author, author)
        
        another_user = utils.create_user()
        
        pn = Actions.replied(another_user, comment)
        
        notifications = expander.expand(pn)
        self.assertTrue(notifications)

        notification = filter(lambda n: n.channel == 'EmailChannel', notifications)[0]
        self.assertEqual(author, notification.recipient)
        
        # Now, let the user unsubscribe to the reply action.
        author.kv.subscriptions.unsubscribe('thread_replied')
        pn = Actions.replied(another_user, comment)
        notifications = expander.expand(pn)
        recipients = [n.recipient for n in notifications if n.channel == 'EmailChannel']
        self.assertFalse(author in recipients)
Пример #9
0
    def test_op_author_expander_notifies_author(self):
        author = utils.create_user()
        comment = utils.create_comment()
        comment.author = author
        comment.save()

        self.assertEqual(comment.thread.op.author, author)

        another_user = utils.create_user()

        pn = Actions.replied(another_user, comment)

        replied_expander = expander.get_expander(pn)()
        notifications = replied_expander.expand(pn)
        recipients = [n.recipient for n in notifications]

        #self.assertEqual(len(recipients), 1)
        self.assertIn(author, recipients)
    def test_op_author_expander_notifies_author(self):
        author = utils.create_user()
        comment = utils.create_comment()
        comment.author = author
        comment.save()

        self.assertEqual(comment.thread.op.author, author)

        another_user = utils.create_user()

        pn = Actions.replied(another_user, comment)

        replied_expander = expander.get_expander(pn)()
        notifications = replied_expander.expand(pn)
        recipients = [n.recipient for n in notifications]

        #self.assertEqual(len(recipients), 1)
        self.assertIn(author, recipients)
Пример #11
0
    def test_replied_op_only_tells_author(self):
        author = create_user()
        content = create_content()
        op = create_comment(author=author, reply_content=content)

        user = create_user()
        reply = create_comment(replied_comment=op, author=user)

        self.assertEqual(reply.replied_comment, op)

        pn = Actions.replied(user, reply)

        notifications = expander.expand(pn)

        for n in notifications:
            print n
        self.assertEqual(len(filter(lambda n: n.channel == 'EmailChannel', notifications)), 1)
        notification = notifications.pop()

        # Note that it will be 'replied', not 'thread_replied'. The former is more specific.
        self.assertEqual(notification.action, 'replied')
Пример #12
0
    def test_user_can_unsubscribe_through_header_link(self):
        user = create_user(email="*****@*****.**")
        comment = create_comment()
        comment2 = create_comment(author=user, replied_comment=comment)

        pn = Actions.replied(user, comment2)
        notification = Notification.from_pending_notification(pn, user, "EmailChannel")

        email_message = EmailChannel().make_message(notification, force=True)
        message = EmailChannel().make_email_backend_message(email_message)
        email_message.record_sent(notification.action)

        assert message.extra_headers
        unsubscribe_link = message.extra_headers.get("List-Unsubscribe")
        assert unsubscribe_link

        # Use should be able to receive notifications ...
        self.assertTrue(user.kv.subscriptions.can_receive('replied'))
        # Now, 'curl' the unsubscribe link
        self.assertStatus(200, unsubscribe_link)
        # Now, this action should be disabled in the notifications subscriptions.
        self.assertFalse(user.kv.subscriptions.can_receive('replied'))
Пример #13
0
    def test_user_can_unsubscribe_through_header_link(self):
        user = create_user(email="*****@*****.**")
        comment = create_comment()
        comment2 = create_comment(author=user, replied_comment=comment)

        pn = Actions.replied(user, comment2)
        notification = Notification.from_pending_notification(pn, user, "EmailChannel")

        email_message = EmailChannel().make_message(notification, force=True)
        message = EmailChannel().make_email_backend_message(email_message)
        email_message.record_sent(notification.action)

        assert message.extra_headers
        unsubscribe_link = message.extra_headers.get("List-Unsubscribe")
        assert unsubscribe_link

        # Use should be able to receive notifications ...
        self.assertTrue(user.kv.subscriptions.can_receive("replied"))
        # Now, 'curl' the unsubscribe link
        self.assertStatus(200, unsubscribe_link)
        # Now, this action should be disabled in the notifications subscriptions.
        self.assertFalse(user.kv.subscriptions.can_receive("replied"))
Пример #14
0
 def do_notify():
     Actions.replied(request.user, comment)
Пример #15
0
 def do_notify():
     Actions.replied(request.user, comment)