def test_resolve_vote_action_item(self): model = ContentType.objects.get_for_model(Poll) items = ActionItem.objects.filter(content_type=model) ok_(not items.exists()) council = Group.objects.get(name='Council') user = UserFactory.create(groups=['Council']) poll = PollFactory.create(valid_groups=council) VoteFactory.create(poll=poll, user=user) items = ActionItem.objects.filter(content_type=model) eq_(items.count(), 1) for item in items: ok_(item.completed) ok_(item.resolved)
def test_resolve_vote_action_item(self): model = ContentType.objects.get_for_model(Poll) items = ActionItem.objects.filter(content_type=model) ok_(not items.exists()) council = Group.objects.get(name='Council') user = UserFactory.create(groups=['Council']) start = now() - timedelta(hours=3) poll = PollFactory.create(valid_groups=council, start=start) VoteFactory.create(poll=poll, user=user) items = ActionItem.objects.filter(content_type=model, object_id=poll.id) eq_(items.count(), 1) for item in items: ok_(item.completed) ok_(item.resolved)
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_user_has_already_voted(self): model = ContentType.objects.get_for_model(Poll) items = ActionItem.objects.filter(content_type=model) ok_(not items.exists()) council = Group.objects.get(name='Admin') user = UserFactory.create(groups=['Admin']) start = now() - timedelta(hours=3) poll = PollFactory.create(valid_groups=council, end=now() - timedelta(days=1), start=start) VoteFactory.create(poll=poll, user=user) # Check that there is only one action item and it's resolved items = ActionItem.objects.filter(content_type=model) eq_(items.count(), 1) eq_(items[0].resolved, True)
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)