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_extend_voting_period_majority(self):
        bug = BugFactory.create()
        start = now().replace(microsecond=0)
        end = datetime.combine(get_date(days=1), datetime.min.time())

        user = UserFactory.create(groups=['Admin'])
        group = Group.objects.get(name='Council')
        User.objects.filter(groups__name='Council').delete()
        UserFactory.create_batch(9, groups=['Council'])

        automated_poll = PollFactoryNoSignals.create(name='poll',
                                                     start=start, end=end,
                                                     valid_groups=group,
                                                     created_by=user,
                                                     automated_poll=True,
                                                     bug=bug)

        radio_poll = RadioPollFactory.create(poll=automated_poll,
                                             question='Budget Approval')
        RadioPollChoiceFactory.create(answer='Approved', votes=5,
                                      radio_poll=radio_poll)
        RadioPollChoiceFactory.create(answer='Denied', votes=3,
                                      radio_poll=radio_poll)

        extend_voting_period()

        poll = Poll.objects.get(pk=automated_poll.id)
        eq_(poll.end.year, end.year)
        eq_(poll.end.month, end.month)
        eq_(poll.end.day, end.day)
        eq_(poll.end.hour, 0)
        eq_(poll.end.minute, 0)
        eq_(poll.end.second, 0)
        ok_(not poll.is_extended)
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_extend_voting_period_no_majority(self):
        bug = BugFactory.create()
        start = now().replace(microsecond=0)
        end = get_date(days=1)
        new_end = get_date(days=2)

        user = UserFactory.create(groups=['Admin'])
        group = Group.objects.get(name='Council')
        User.objects.filter(groups__name='Council').delete()
        council = UserFactory.create_batch(9, groups=['Council'])

        automated_poll = PollFactoryNoSignals.create(name='poll',
                                                     start=start,
                                                     end=end,
                                                     valid_groups=group,
                                                     created_by=user,
                                                     automated_poll=True,
                                                     bug=bug)

        radio_poll = RadioPollFactory.create(poll=automated_poll,
                                             question='Budget Approval')
        RadioPollChoiceFactory.create(answer='Approved',
                                      votes=3,
                                      radio_poll=radio_poll)
        RadioPollChoiceFactory.create(answer='Denied',
                                      votes=4,
                                      radio_poll=radio_poll)
        VoteFactory.create(user=council[0], poll=automated_poll)

        extend_voting_period()

        poll = Poll.objects.get(pk=automated_poll.id)
        eq_(poll.end.year, new_end.year)
        eq_(poll.end.month, new_end.month)
        eq_(poll.end.day, new_end.day)
        eq_(poll.end.hour, 0)
        eq_(poll.end.minute, 0)
        eq_(poll.end.second, 0)
        ok_(poll.is_extended)

        reminders = map(lambda x: x.subject, mail.outbox)
        msg = '[Urgent] Voting extended for poll'

        # Test that those who voted don't receive notification
        eq_(reminders.count(msg), 8)
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
        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 #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_extend_voting_period_no_majority(self):
        bug = BugFactory.create()
        start = now().replace(microsecond=0)
        end = datetime.combine(get_date(days=1), datetime.min.time())
        new_end = datetime.combine(get_date(days=2), datetime.min.time())

        user = UserFactory.create(groups=['Admin'])
        group = Group.objects.get(name='Council')
        User.objects.filter(groups__name='Council').delete()
        council = UserFactory.create_batch(9, groups=['Council'])

        automated_poll = PollFactoryNoSignals.create(name='poll',
                                                     start=start, end=end,
                                                     valid_groups=group,
                                                     created_by=user,
                                                     automated_poll=True,
                                                     bug=bug)

        radio_poll = RadioPollFactory.create(poll=automated_poll,
                                             question='Budget Approval')
        RadioPollChoiceFactory.create(answer='Approved', votes=3,
                                      radio_poll=radio_poll)
        RadioPollChoiceFactory.create(answer='Denied', votes=4,
                                      radio_poll=radio_poll)
        VoteFactory.create(user=council[0], poll=automated_poll)

        extend_voting_period()

        poll = Poll.objects.get(pk=automated_poll.id)
        eq_(poll.end.year, new_end.year)
        eq_(poll.end.month, new_end.month)
        eq_(poll.end.day, new_end.day)
        eq_(poll.end.hour, 0)
        eq_(poll.end.minute, 0)
        eq_(poll.end.second, 0)
        ok_(poll.is_extended)

        reminders = map(lambda x: x.subject, mail.outbox)
        msg = '[Urgent] Voting extended for poll'

        # Test that those who voted don't receive notification
        eq_(reminders.count(msg), 8)