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)
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)
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)
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)
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)
def setUp(self): """Initial data for the tests.""" self.nominee1, self.nominee2, self.nominee3 = UserFactory.create_batch(3, groups=['Rep']) self.rep = UserFactory.create(groups=['Rep']) self.admin = UserFactory.create(groups=['Admin', 'Rep']) self.mozillian = UserFactory.create(groups=['Mozillians']) poll_start = now() + timedelta(days=5) self.admin_group = Group.objects.get(name='Admin') self.rep_group = Group.objects.get(name='Rep') self.poll = PollFactory.create(valid_groups=self.admin_group, start=poll_start, end=poll_start + timedelta(days=10), comments_allowed=False) self.range_poll = RangePollFactory(poll=self.poll) self.range_poll_choice1 = RangePollChoiceFactory(range_poll=self.range_poll, nominee=self.nominee1) self.range_poll_choice2 = RangePollChoiceFactory(range_poll=self.range_poll, nominee=self.nominee2) self.radio_poll = RadioPollFactory(poll=self.poll) self.radio_poll_choice1, self.radio_poll_choice2 = RadioPollChoiceFactory.create_batch( 2, radio_poll=self.radio_poll) self.post_data = {'range_poll__1': 1, 'range_poll__2': 2, 'radio_poll__1': 2} self.edit_future_data = { 'name': u'Test edit voting', 'description': u'This is a description.', 'created_by': self.poll.created_by.id, 'valid_groups': self.admin_group.id, 'start_form_0_year': now().year + 1, 'start_form_0_month': 10, 'start_form_0_day': 1, 'start_form_1_hour': 7, 'start_form_1_minute': 00, 'end_form_0_year': now().year + 1, 'end_form_0_month': 10, 'end_form_0_day': 4, 'end_form_1_hour': 7, 'end_form_1_minute': 00, 'range_polls-TOTAL_FORMS': u'1', 'range_polls-INITIAL_FORMS': u'1', 'range_polls-MAX_NUM_FORMS': u'1000', 'range_polls-0-id': self.range_poll.id, 'range_polls-0-name': u'Current Range Poll 1', '{0}_range_choices-0-id'.format(self.range_poll.id): self.range_poll_choice1.id, '{0}_range_choices-0-nominee'.format(self.range_poll.id): self.nominee1.id, '{0}_range_choices-0-DELETE'.format(self.range_poll.id): False, '{0}_range_choices-1-id'.format(self.range_poll.id): self.range_poll_choice2.id, '{0}_range_choices-1-nominee'.format(self.range_poll.id): self.nominee2.id, '{0}_range_choices-1-DELETE'.format(self.range_poll.id): False, '{0}_range_choices-2-id'.format(self.range_poll.id): u'', '{0}_range_choices-2-nominee'.format(self.range_poll.id): self.nominee3.id, '{0}_range_choices-2-DELETE'.format(self.range_poll.id): False, '{0}_range_choices-TOTAL_FORMS'.format(self.range_poll.id): u'3', '{0}_range_choices-INITIAL_FORMS'.format(self.range_poll.id): u'2', '{0}_range_choices-TOTAL_FORMS'.format(self.range_poll.id): u'1000', 'radio_polls-0-id': self.radio_poll.id, 'radio_polls-0-question': u'Radio Poll - Question 1', 'radio_polls-TOTAL_FORMS': u'1', 'radio_polls-INITIAL_FORMS': u'1', 'radio_polls-MAX_NUM_FORMS': u'1000', '{0}_radio_choices-TOTAL_FORMS'.format(self.radio_poll.id): u'2', '{0}_radio_choices-INITIAL_FORMS'.format(self.radio_poll.id): u'2', '{0}_radio_choices-MAX_NUM_FORMS'.format(self.radio_poll.id): u'1000', '{0}_radio_choices-0-id'.format(self.radio_poll.id): self.radio_poll_choice1.id, '{0}_radio_choices-0-answer'.format(self.radio_poll.id): u'Radio Poll - Answer 1', '{0}_radio_choices-0-DELETE'.format(self.radio_poll.id): False, '{0}_radio_choices-1-id'.format(self.radio_poll.id): self.radio_poll_choice2.id, '{0}_radio_choices-1-answer'.format(self.radio_poll.id): u'Radio Poll - Answer 2', '{0}_radio_choices-1-DELETE'.format(self.radio_poll.id): False} self.edit_current_data = { 'name': u'Test edit voting', 'description': u'This is a description.', 'created_by': self.nominee1.id, 'valid_groups': self.admin_group.id, 'start_form_0_year': 2011, 'end_form_0_year': now().year, 'end_form_0_month': 10, 'end_form_0_day': 4, 'end_form_1_hour': 7, 'end_form_1_minute': 00} # Give permissions to admin group group = Group.objects.get(name='Admin') permissions = Permission.objects.filter(name__icontains='poll') for perm in permissions: group.permissions.add(perm)
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)
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)
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))