Exemplo n.º 1
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)
Exemplo n.º 2
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)
Exemplo n.º 3
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='Review')
        User.objects.filter(groups__name='Review').delete()
        review = UserFactory.create_batch(9, groups=['Review'])

        with mute_signals(post_save):
            automated_poll = PollFactory.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=review[0], poll=automated_poll)

        with patch('remo.voting.tasks.send_remo_mail.delay') as mocked_mail:
            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)

        # Test that only the 1 that hasn't voted gets a notification
        ok_(mocked_mail.called)
        eq_(mocked_mail.call_count, 1)
Exemplo n.º 4
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)
Exemplo n.º 5
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='Review')
        User.objects.filter(groups__name='Review').delete()
        review = UserFactory.create_batch(9, groups=['Review'])

        with mute_signals(post_save):
            automated_poll = PollFactory.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=review[0], poll=automated_poll)

        with patch('remo.voting.tasks.send_remo_mail.delay') as mocked_mail:
            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)

        # Test that only the 1 that hasn't voted gets a notification
        ok_(mocked_mail.called)
        eq_(mocked_mail.call_count, 1)
Exemplo n.º 6
0
    def setUp(self):
        """Initial setup for the tests."""
        self.poll = PollFactory.create()
        self.radio_poll = RadioPollFactory.create(poll=self.poll)
        self.radio_poll_choice = (
            RadioPollChoiceFactory.create(radio_poll=self.radio_poll))
        self.range_poll = RangePollFactory.create(poll=self.poll)
        self.range_poll_choice = (
            RangePollChoiceFactory.create(range_poll=self.range_poll))
        UserFactory.create_batch(20, groups=['Rep'])
        self.user_list = (
            User.objects.filter(groups__name='Rep',
                                userprofile__registration_complete=True))
        self.user = self.user_list[0]

        self.form_data = {
            'description': u'This is a description.',
            'end_form_0_day': u'10',
            'end_form_0_month': u'2',
            'end_form_0_year': u'{0}'.format(now().year + 2),
            'end_form_1_hour': u'12',
            'end_form_1_minute': u'00',
            'name': u'Form data.',
            'start_form_0_day': u'10',
            'start_form_0_month': u'2',
            'start_form_0_year': u'{0}'.format(now().year + 1),
            'start_form_1_hour': u'12',
            'start_form_1_minute': u'00',
            'valid_groups': u'1'}

        self.radio_formset_data = {
            'radio_polls-0-id': u'%d' % self.radio_poll.id,
            'radio_polls-0-question': u'Radio Poll Example 2 - Question 1',
            'radio_polls-TOTAL_FORMS': u'1',
            'radio_polls-INITIAL_FORMS': u'1',
            'radio_polls-MAX_NUM_FORMS': u'1000',
            '%d_radio_choices-TOTAL_FORMS' % self.radio_poll.id: u'1',
            '%d_radio_choices-INITIAL_FORMS' % self.radio_poll.id: u'1',
            '%d_radio_choices-MAX_NUM_FORMS' % self.radio_poll.id: u'1000',
            '%d_radio_choices-0-id' % self.radio_poll.id: (
                u'%d' % self.radio_poll_choice.id),
            '%d_radio_choices-0-answer' % self.radio_poll.id: u'Answer 1',
            '%d_radio_choices-0-DELETE' % self.radio_poll.id: False}

        self.range_formset_data = {
            'range_polls-TOTAL_FORMS': u'1',
            'range_polls-INITIAL_FORMS': u'1',
            'range_polls-MAX_NUM_FORMS': u'1000',
            'range_polls-0-id': u'%d' % self.range_poll.id,
            'range_polls-0-name': u'Current Range Poll 1',
            '%d_range_choices-0-id' % self.range_poll.id: (
                u'%d' % self.range_poll.id),
            '%d_range_choices-0-nominee' % self.range_poll.id: (
                u'%d' % self.user.id),
            '%d_range_choices-0-DELETE' % self.range_poll.id: False,
            '%d_range_choices-TOTAL_FORMS' % self.range_poll.id: u'1',
            '%d_range_choices-INITIAL_FORMS' % self.range_poll.id: u'1',
            '%d_range_choices-MAX_NUM_FORMS' % self.range_poll.id: u'1000'}

        self.empty_radio_formset = {
            'radio_polls-TOTAL_FORMS': u'0',
            'radio_polls-INITIAL_FORMS': u'0',
            'radio_polls-MAX_NUM_FORMS': u'1000'}

        self.empty_range_formset = {
            'range_polls-TOTAL_FORMS': u'0',
            'range_polls-INITIAL_FORMS': u'0',
            'range_polls-MAX_NUM_FORMS': u'1000'}

        RangePollFormset = inlineformset_factory(Poll,
                                                 RangePoll,
                                                 formset=forms.BaseRangePollInlineFormSet,
                                                 extra=1,
                                                 exclude=('votes',),
                                                 can_delete=True)
        RadioPollFormset = inlineformset_factory(Poll,
                                                 RadioPoll,
                                                 formset=forms.BaseRadioPollInlineFormSet,
                                                 extra=1,
                                                 can_delete=True,
                                                 exclude=('votes',))

        self.range_poll_formset = RangePollFormset(self.range_formset_data,
                                                   instance=self.poll,
                                                   user_list=self.user_list)
        self.radio_poll_formset = RadioPollFormset(self.radio_formset_data, instance=self.poll)
        self.radio_poll_formset_empty = RadioPollFormset(self.empty_radio_formset,
                                                         instance=self.poll)
        self.range_poll_formset_empty = RangePollFormset(self.empty_range_formset,
                                                         instance=self.poll,
                                                         user_list=self.user_list)
Exemplo n.º 7
0
    def setUp(self):
        """Initial setup for the tests."""
        self.poll = PollFactory.create()
        self.radio_poll = RadioPollFactory.create(poll=self.poll)
        self.radio_poll_choice = (RadioPollChoiceFactory
                                  .create(radio_poll=self.radio_poll))
        self.range_poll = RangePollFactory.create(poll=self.poll)
        self.range_poll_choice = (RangePollChoiceFactory
                                  .create(range_poll=self.range_poll))

        self.form_data = {
            'description': u'This is a description.',
            'end_form_0_day': u'1',
            'end_form_0_month': u'1',
            'end_form_0_year': u'2019',
            'end_form_1_hour': u'12',
            'end_form_1_minute': u'00',
            'name': u'Form data.',
            'start_form_0_day': u'1',
            'start_form_0_month': u'1',
            'start_form_0_year': u'2018',
            'start_form_1_hour': u'12',
            'start_form_1_minute': u'00',
            'valid_groups': u'1'}

        self.radio_formset_data = {
            'radio_polls-0-id': u'%s' % str(self.radio_poll.id),
            'radio_polls-0-question': u'Radio Poll Example 2 - Question 1',
            'radio_polls-TOTAL_FORMS': u'1',
            'radio_polls-INITIAL_FORMS': u'1',
            'radio_polls-MAX_NUM_FORMS': u'1000',
            '%s_radio_choices-TOTAL_FORMS' % str(self.radio_poll.id): u'1',
            '%s_radio_choices-INITIAL_FORMS' % str(self.radio_poll.id): u'1',
            '%s_radio_choices-MAX_NUM_FORMS' % (
                str(self.radio_poll.id)): u'1000',
            '%s_radio_choices-0-id' % str(self.radio_poll.id): u'1',
            '%s_radio_choices-0-answer' % str(self.radio_poll.id): u'Answer 1',
            '%s_radio_choices-0-DELETE' % str(self.radio_poll.id): False}

        self.range_formset_data = {
            'range_polls-TOTAL_FORMS': u'1',
            'range_polls-INITIAL_FORMS': u'1',
            'range_polls-MAX_NUM_FORMS': u'1000',
            'range_polls-0-id': u'%s' % str(self.range_poll.id),
            'range_polls-0-name': u'Current Range Poll 1',
            '%s_range_choices-0-id' % str(self.range_poll.id): u'1',
            '%s_range_choices-0-nominee' % self.range_poll.id: u'4',
            '%s_range_choices-0-DELETE' % str(self.range_poll.id): False,
            '%s_range_choices-TOTAL_FORMS' % str(self.range_poll.id): u'1',
            '%s_range_choices-INITIAL_FORMS' % str(self.range_poll.id): u'1',
            '%s_range_choices-MAX_NUM_FORMS' % (
                str(self.range_poll.id)): u'1000'}

        self.radio_formset_invalid_data = {
            'radio_polls-TOTAL_FORMS': u'0',
            'radio_polls-INITIAL_FORMS': u'0',
            'radio_polls-MAX_NUM_FORMS': u'1000',
            '%s_radio_choices-TOTAL_FORMS' % str(self.radio_poll.id): u'0',
            '%s_radio_choices-INITIAL_FORMS' % str(self.radio_poll.id): u'0',
            '%s_radio_choices-MAX_NUM_FORMS' % (
                str(self.radio_poll.id)): u'1000'}

        self.range_formset_invalid_data = {
            'range_polls-TOTAL_FORMS': u'0',
            'range_polls-INITIAL_FORMS': u'0',
            'range_polls-MAX_NUM_FORMS': u'1000',
            '%s_range_choices-TOTAL_FORMS' % str(self.range_poll.id): u'0',
            '%s_range_choices-INITIAL_FORMS' % str(self.range_poll.id): u'0',
            '%s_range_choices-TOTAL_FORMS' % (
                str(self.range_poll.id)): u'1000'}

        RangePollFormset = (inlineformset_factory(Poll, RangePoll,
                            formset=forms.BaseRangePollInlineFormSet,
                            extra=1, can_delete=True))
        RadioPollFormset = (inlineformset_factory(Poll, RadioPoll,
                            formset=forms.BaseRadioPollInlineFormSet,
                            extra=1, can_delete=True))
        self.range_poll_formset = RangePollFormset(self.range_formset_data,
                                                   instance=self.poll)
        self.radio_poll_formset = RadioPollFormset(self.radio_formset_data,
                                                   instance=self.poll)
        self.radio_poll_formset_invalid = RadioPollFormset(
            self.radio_formset_invalid_data, instance=self.poll)
        self.range_poll_formset_invalid = RangePollFormset(
            self.range_formset_invalid_data, instance=self.poll)
Exemplo n.º 8
0
    def setUp(self):
        """Initial setup for the tests."""
        self.poll = PollFactory.create()
        self.radio_poll = RadioPollFactory.create(poll=self.poll)
        self.radio_poll_choice = (RadioPollChoiceFactory.create(
            radio_poll=self.radio_poll))
        self.range_poll = RangePollFactory.create(poll=self.poll)
        self.range_poll_choice = (RangePollChoiceFactory.create(
            range_poll=self.range_poll))
        UserFactory.create_batch(20, groups=['Rep'])
        self.user_list = (User.objects.filter(
            groups__name='Rep', userprofile__registration_complete=True))
        self.user = self.user_list[0]

        self.form_data = {
            'description': u'This is a description.',
            'end_form_0_day': u'1',
            'end_form_0_month': u'1',
            'end_form_0_year': u'2019',
            'end_form_1_hour': u'12',
            'end_form_1_minute': u'00',
            'name': u'Form data.',
            'start_form_0_day': u'1',
            'start_form_0_month': u'1',
            'start_form_0_year': u'2018',
            'start_form_1_hour': u'12',
            'start_form_1_minute': u'00',
            'valid_groups': u'1'
        }

        self.radio_formset_data = {
            'radio_polls-0-id':
            u'%d' % self.radio_poll.id,
            'radio_polls-0-question':
            u'Radio Poll Example 2 - Question 1',
            'radio_polls-TOTAL_FORMS':
            u'1',
            'radio_polls-INITIAL_FORMS':
            u'1',
            'radio_polls-MAX_NUM_FORMS':
            u'1000',
            '%d_radio_choices-TOTAL_FORMS' % self.radio_poll.id:
            u'1',
            '%d_radio_choices-INITIAL_FORMS' % self.radio_poll.id:
            u'1',
            '%d_radio_choices-MAX_NUM_FORMS' % self.radio_poll.id:
            u'1000',
            '%d_radio_choices-0-id' % self.radio_poll.id:
            (u'%d' % self.radio_poll_choice.id),
            '%d_radio_choices-0-answer' % self.radio_poll.id:
            u'Answer 1',
            '%d_radio_choices-0-DELETE' % self.radio_poll.id:
            False
        }

        self.range_formset_data = {
            'range_polls-TOTAL_FORMS':
            u'1',
            'range_polls-INITIAL_FORMS':
            u'1',
            'range_polls-MAX_NUM_FORMS':
            u'1000',
            'range_polls-0-id':
            u'%d' % self.range_poll.id,
            'range_polls-0-name':
            u'Current Range Poll 1',
            '%d_range_choices-0-id' % self.range_poll.id:
            (u'%d' % self.range_poll.id),
            '%d_range_choices-0-nominee' % self.range_poll.id:
            (u'%d' % self.user.id),
            '%d_range_choices-0-DELETE' % self.range_poll.id:
            False,
            '%d_range_choices-TOTAL_FORMS' % self.range_poll.id:
            u'1',
            '%d_range_choices-INITIAL_FORMS' % self.range_poll.id:
            u'1',
            '%d_range_choices-MAX_NUM_FORMS' % self.range_poll.id:
            u'1000'
        }

        self.empty_radio_formset = {
            'radio_polls-TOTAL_FORMS': u'0',
            'radio_polls-INITIAL_FORMS': u'0',
            'radio_polls-MAX_NUM_FORMS': u'1000'
        }

        self.empty_range_formset = {
            'range_polls-TOTAL_FORMS': u'0',
            'range_polls-INITIAL_FORMS': u'0',
            'range_polls-MAX_NUM_FORMS': u'1000'
        }

        RangePollFormset = inlineformset_factory(
            Poll,
            RangePoll,
            formset=forms.BaseRangePollInlineFormSet,
            extra=1,
            can_delete=True)
        RadioPollFormset = inlineformset_factory(
            Poll,
            RadioPoll,
            formset=forms.BaseRadioPollInlineFormSet,
            extra=1,
            can_delete=True)

        self.range_poll_formset = (RangePollFormset(self.range_formset_data,
                                                    instance=self.poll,
                                                    user_list=self.user_list))
        self.radio_poll_formset = (RadioPollFormset(self.radio_formset_data,
                                                    instance=self.poll))
        self.radio_poll_formset_empty = (RadioPollFormset(
            self.empty_radio_formset, instance=self.poll))
        self.range_poll_formset_empty = (RangePollFormset(
            self.empty_range_formset,
            instance=self.poll,
            user_list=self.user_list))