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)
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)
def test_digest_expander(self): user = create_user() pn = Actions.digest(user) notifications = expander.expand(pn) self.assertEqual(len(notifications), 1) notification = notifications.pop() self.assertEqual(notification.recipient, user)
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_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)
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')
def test_newsletter_expander_for_user_with_no_email(self): user = create_user(email="") pn = Actions.newsletter(user) self.assertFalse(user.email) notifications = expander.expand(pn) self.assertEqual(len(notifications), 0)