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)