Beispiel #1
0
    def test_comment_multiple_users(self):
        """Test sending email when a new comment is added on a Poll
        and the users have the option enabled in their settings.
        """
        commenter = UserFactory.create()
        creator = UserFactory.create(
            userprofile__receive_email_on_add_voting_comment=True)
        poll = PollFactoryNoSignals.create(created_by=creator)
        users_with_comments = UserFactory.create_batch(
            2, userprofile__receive_email_on_add_voting_comment=True)
        # disconnect the signals in order to add two users in PollComment
        for user_obj in users_with_comments:
            PollCommentFactoryNoSignals.create(user=user_obj,
                                               poll=poll,
                                               comment='This is a comment')
        PollCommentFactory.create(user=commenter,
                                  poll=poll,
                                  comment='This is a comment')

        eq_(len(mail.outbox), 3)
        recipients = [
            '%s <%s>' % (creator.get_full_name(), creator.email),
            '%s <%s>' % (users_with_comments[0].get_full_name(),
                         users_with_comments[0].email),
            '%s <%s>' % (users_with_comments[1].get_full_name(),
                         users_with_comments[1].email)
        ]
        receivers = [
            mail.outbox[0].to[0], mail.outbox[1].to[0], mail.outbox[2].to[0]
        ]
        eq_(set(recipients), set(receivers))
        msg = ('[Voting] User {0} commented on {1}'.format(
            commenter.get_full_name(), poll))
        eq_(mail.outbox[0].subject, msg)
Beispiel #2
0
    def test_comment_multiple_users(self):
        """Test sending email when a new comment is added on a Poll
        and the users have the option enabled in their settings.
        """
        commenter = UserFactory.create()
        creator = UserFactory.create(
            userprofile__receive_email_on_add_voting_comment=True)
        poll = PollFactoryNoSignals.create(created_by=creator)
        users_with_comments = UserFactory.create_batch(
            2, userprofile__receive_email_on_add_voting_comment=True)
        # disconnect the signals in order to add two users in PollComment
        for user_obj in users_with_comments:
            PollCommentFactoryNoSignals.create(
                user=user_obj, poll=poll, comment='This is a comment')
        PollCommentFactory.create(user=commenter, poll=poll,
                                  comment='This is a comment')

        eq_(len(mail.outbox), 3)
        recipients = ['%s <%s>' % (creator.get_full_name(), creator.email),
                      '%s <%s>' % (users_with_comments[0].get_full_name(),
                                   users_with_comments[0].email),
                      '%s <%s>' % (users_with_comments[1].get_full_name(),
                                   users_with_comments[1].email)]
        receivers = [mail.outbox[0].to[0], mail.outbox[1].to[0],
                     mail.outbox[2].to[0]]
        eq_(set(recipients), set(receivers))
        msg = ('[Voting] User {0} commented on {1}'
               .format(commenter.get_full_name(), poll))
        eq_(mail.outbox[0].subject, msg)
Beispiel #3
0
 def test_one_user_settings_False(self):
     """Test sending email when a new comment is added on a Poll
     and the user has the option disabled in his/her settings.
     """
     commenter = UserFactory.create()
     user = UserFactory.create(userprofile__receive_email_on_add_voting_comment=False)
     with mute_signals(post_save):
         poll = PollFactory.create(created_by=user)
     with patch('remo.voting.models.send_remo_mail.delay') as mail_mock:
         PollCommentFactory.create(user=commenter, poll=poll, comment='This is a comment')
     ok_(not mail_mock.called)
Beispiel #4
0
    def test_one_user_settings_False(self):
        """Test sending email when a new comment is added on a Poll
        and the user has the option disabled in his/her settings.
        """
        comment_user = UserFactory.create()
        user = UserFactory.create(
            userprofile__receive_email_on_add_voting_comment=False)
        poll = PollFactoryNoSignals.create(created_by=user)
        PollCommentFactory.create(user=comment_user, poll=poll,
                                  comment='This is a comment')

        eq_(len(mail.outbox), 0)
Beispiel #5
0
    def test_one_user_settings_False(self):
        """Test sending email when a new comment is added on a Poll
        and the user has the option disabled in his/her settings.
        """
        comment_user = UserFactory.create()
        user = UserFactory.create(
            userprofile__receive_email_on_add_voting_comment=False)
        poll = PollFactoryNoSignals.create(created_by=user)
        PollCommentFactory.create(user=comment_user,
                                  poll=poll,
                                  comment='This is a comment')

        eq_(len(mail.outbox), 0)
Beispiel #6
0
 def test_one_user_settings_False(self):
     """Test sending email when a new comment is added on a Poll
     and the user has the option disabled in his/her settings.
     """
     commenter = UserFactory.create()
     user = UserFactory.create(
         userprofile__receive_email_on_add_voting_comment=False)
     with mute_signals(post_save):
         poll = PollFactory.create(created_by=user)
     with patch('remo.voting.models.send_remo_mail.delay') as mail_mock:
         PollCommentFactory.create(user=commenter,
                                   poll=poll,
                                   comment='This is a comment')
     ok_(not mail_mock.called)
Beispiel #7
0
    def test_comment_one_user(self):
        """Test sending email when a new comment is added on a Poll
        and the user has the option enabled in his/her settings.
        """
        commenter = UserFactory.create()
        creator = UserFactory.create(
            userprofile__receive_email_on_add_voting_comment=True)
        # Disable notifications related to the creation of a poll
        with mute_signals(post_save):
            poll = PollFactory.create(created_by=creator)

        with patch('remo.voting.models.send_remo_mail.delay') as mail_mock:
            PollCommentFactory.create(user=commenter, poll=poll, comment='This is a comment')

        ok_(mail_mock.called)
        eq_(mail_mock.call_count, 1)
Beispiel #8
0
    def test_comment_one_user(self):
        """Test sending email when a new comment is added on a Poll
        and the user has the option enabled in his/her settings.
        """
        commenter = UserFactory.create()
        creator = UserFactory.create(
            userprofile__receive_email_on_add_voting_comment=True)
        # Disable notifications related to the creation of a poll
        poll = PollFactoryNoSignals.create(created_by=creator)
        PollCommentFactory.create(user=commenter, poll=poll,
                                  comment='This is a comment')

        eq_(len(mail.outbox), 1)
        eq_('%s <%s>' % (creator.get_full_name(), creator.email),
            mail.outbox[0].to[0])
        msg = ('[Voting] User {0} commented on {1}'
               .format(commenter.get_full_name(), poll))
        eq_(mail.outbox[0].subject, msg)
Beispiel #9
0
    def test_comment_one_user(self):
        """Test sending email when a new comment is added on a Poll
        and the user has the option enabled in his/her settings.
        """
        commenter = UserFactory.create()
        creator = UserFactory.create(
            userprofile__receive_email_on_add_voting_comment=True)
        # Disable notifications related to the creation of a poll
        with mute_signals(post_save):
            poll = PollFactory.create(created_by=creator)

        with patch('remo.voting.models.send_remo_mail.delay') as mail_mock:
            PollCommentFactory.create(user=commenter,
                                      poll=poll,
                                      comment='This is a comment')

        ok_(mail_mock.called)
        eq_(mail_mock.call_count, 1)
Beispiel #10
0
 def test_delete_as_other_rep(self):
     user = UserFactory.create(groups=['Rep'])
     group = Group.objects.get(name='Rep')
     poll = PollFactory.create(created_by=user, valid_groups=group)
     comment = PollCommentFactory.create(poll=poll, user=user,
                                         comment='This is a comment')
     other_rep = UserFactory.create(groups=['Rep'])
     self.post(user=other_rep, url=comment.get_absolute_delete_url())
     ok_(PollComment.objects.filter(pk=comment.id).exists())
Beispiel #11
0
 def test_delete_as_other_rep(self):
     user = UserFactory.create(groups=['Rep'])
     group = Group.objects.get(name='Rep')
     poll = PollFactory.create(created_by=user, valid_groups=group)
     comment = PollCommentFactory.create(poll=poll, user=user,
                                         comment='This is a comment')
     other_rep = UserFactory.create(groups=['Rep'])
     with self.login(other_rep) as client:
         client.post(comment.get_absolute_delete_url(), user=other_rep)
     ok_(PollComment.objects.filter(pk=comment.id).exists())
Beispiel #12
0
 def test_delete_as_owner(self, redirect_mock):
     user = UserFactory.create(groups=['Rep'])
     group = Group.objects.get(name='Rep')
     poll = PollFactory.create(created_by=user, valid_groups=group)
     comment = PollCommentFactory.create(poll=poll, user=user,
                                         comment='This is a comment')
     with self.login(user) as client:
         client.post(comment.get_absolute_delete_url(), user=comment.user)
     ok_(not PollComment.objects.filter(pk=comment.id).exists())
     redirect_mock.assert_called_with(poll.get_absolute_url())
Beispiel #13
0
    def test_comment_one_user(self):
        """Test sending email when a new comment is added on a Poll
        and the user has the option enabled in his/her settings.
        """
        commenter = UserFactory.create()
        creator = UserFactory.create(
            userprofile__receive_email_on_add_voting_comment=True)
        # Disable notifications related to the creation of a poll
        poll = PollFactoryNoSignals.create(created_by=creator)
        PollCommentFactory.create(user=commenter,
                                  poll=poll,
                                  comment='This is a comment')

        eq_(len(mail.outbox), 1)
        eq_('%s <%s>' % (creator.get_full_name(), creator.email),
            mail.outbox[0].to[0])
        msg = ('[Voting] User {0} commented on {1}'.format(
            commenter.get_full_name(), poll))
        eq_(mail.outbox[0].subject, msg)
Beispiel #14
0
 def test_delete_as_admin(self, redirect_mock):
     user = UserFactory.create(groups=['Admin'])
     comment = PollCommentFactory.create()
     with self.login(user) as client:
         client.post(comment.get_absolute_delete_url(), user=user)
     ok_(not PollComment.objects.filter(pk=comment.id).exists())
Beispiel #15
0
 def test_delete_as_anonymous(self):
     comment = PollCommentFactory.create()
     client = Client()
     client.post(comment.get_absolute_delete_url(), data={})
     ok_(PollComment.objects.filter(pk=comment.id).exists())