class VotingMailNotificationTest(TestCase): """Tests related to Voting Models.""" fixtures = ['demo_users.json'] def setUp(self): """Initial data for the tests.""" self.user = User.objects.get(username='******') self.group = Group.objects.get(name='Admin') self._now = timezone.make_aware(datetime.datetime.now(), pytz.timezone(settings.TIME_ZONE)) self.now = self._now.replace(microsecond=0) self.start = self.now self.end = self.now + datetime.timedelta(days=5) self.voting = Poll(name='poll', start=self.start, end=self.end, valid_groups=self.group, created_by=self.user) self.voting.save() def test_send_email_on_save_poll(self): """Test sending emails when a new voting is added.""" eq_(len(mail.outbox), 2) @fudge.patch('remo.voting.models.celery_control.revoke') def test_send_email_on_edit_poll(self, fake_requests_obj): """Test sending emails when the poll is edited.""" Poll.objects.filter(pk=self.voting.id).update(task_start_id='1234', task_end_id='1234') poll = Poll.objects.get(pk=self.voting.id) poll.name = 'Edit Voting' if not settings.CELERY_ALWAYS_EAGER: (fake_requests_obj.expects_call().returns(True)) poll.save() eq_(len(mail.outbox), 3)
class VotingMailNotificationTest(TestCase): """Tests related to Voting Models.""" fixtures = ['demo_users.json'] def setUp(self): """Initial data for the tests.""" self.user = User.objects.get(username='******') self.group = Group.objects.get(name='Admin') self._now = now() self.now = self._now.replace(microsecond=0) self.start = self.now self.end = self.now + datetime.timedelta(days=5) self.voting = Poll(name='poll', start=self.start, end=self.end, valid_groups=self.group, created_by=self.user) self.voting.save() def test_send_email_on_save_poll(self): """Test sending emails when a new voting is added.""" recipients = map(lambda x: '%s' % x.email, User.objects.filter(groups=self.group)) eq_(len(mail.outbox), 2) ok_(mail.outbox[0].to[0] in recipients) ok_(mail.outbox[1].to[0] in recipients) @patch('remo.voting.models.celery_control.revoke') def test_send_email_on_edit_poll(self, fake_revoke): """Test sending emails when the poll is edited.""" Poll.objects.filter(pk=self.voting.id).update(task_start_id='1234', task_end_id='1234') poll = Poll.objects.get(pk=self.voting.id) poll.name = 'Edit Voting' if not settings.CELERY_ALWAYS_EAGER: fake_revoke.return_value = True poll.save() eq_(len(mail.outbox), 3)
class VotingTestCommands(TestCase): """Test sending notifications.""" fixtures = ['demo_users.json'] def setUp(self): """Initial data for the tests.""" self.user = User.objects.get(username='******') self.group = Group.objects.get(name='Admin') self._now = timezone.make_aware(datetime.datetime.utcnow(), pytz.UTC) self.now = self._now.replace(microsecond=0) self.start = self.now self.end = self.now + datetime.timedelta(days=5) self.voting = Poll(name='poll', start=self.start, end=self.end, valid_groups=self.group, created_by=self.user) self.voting.save() @fudge.patch('remo.voting.cron.datetime.datetime.utcnow') def test_email_users_without_a_vote(self, fake_requests_obj): """Test sending an email to users who have not cast their vote yet. """ # act like it's today + 1 day tomorrow = datetime.datetime.today() + datetime.timedelta(days=1) (fake_requests_obj.expects_call().returns(tomorrow)) args = ['poll_vote_reminder'] management.call_command('cron', *args) eq_(len(mail.outbox), 3)
class VotingTestCommands(TestCase): """Test sending notifications.""" fixtures = ['demo_users.json'] def setUp(self): """Initial data for the tests.""" self.user = User.objects.get(username='******') self.group = Group.objects.get(name='Council') self._now = datetime2pdt() self.now = self._now.replace(microsecond=0) self.start = self.now self.end = self.now + datetime.timedelta(hours=5 * 24) self.voting = Poll(name='poll', start=self.start, end=self.end, valid_groups=self.group, created_by=self.user) self.voting.save() @patch('remo.voting.cron.datetime2pdt') def test_email_users_without_a_vote(self, fake_datetime2pdt): """Test sending an email to users who have not cast their vote yet. """ # act like it's today + 1 day fake_datetime2pdt.return_value = (datetime2pdt() + datetime.timedelta(days=1)) args = ['poll_vote_reminder'] management.call_command('cron', *args) eq_(len(mail.outbox), 3) for email in mail.outbox: eq_(email.to, ['*****@*****.**']) @patch('remo.voting.cron.datetime2pdt') def test_extend_voting_period_by_24hours(self, fake_datetime2pdt): """Test extending voting period by 24hours if less than 50% of the valid users have voted and the poll ends in less than 8 hours. """ automated_poll = Poll(name='poll', start=self.start, end=self.end, valid_groups=self.group, created_by=self.user, automated_poll=True) automated_poll.save() # act like it's 4 hours before the end of the poll fake_datetime2pdt.return_value = (datetime2pdt() + datetime.timedelta(hours=116)) args = ['extend_voting_period'] management.call_command('cron', *args) poll = Poll.objects.get(pk=automated_poll.id) eq_(poll.end - automated_poll.end, datetime.timedelta(hours=24))
class VotingMailNotificationTest(TestCase): """Tests related to Voting Models.""" fixtures = ['demo_users.json'] def setUp(self): """Initial data for the tests.""" self.user = User.objects.get(username='******') self.group = Group.objects.get(name='Admin') self._now = datetime2pdt() self.now = self._now.replace(microsecond=0) self.start = self.now self.end = self.now + datetime.timedelta(days=5) self.voting = Poll(name='poll', start=self.start, end=self.end, valid_groups=self.group, created_by=self.user) self.voting.save() def test_send_email_on_save_poll(self): """Test sending emails when a new voting is added.""" recipients = map(lambda x: '%s' % x.email, User.objects.filter(groups=self.group)) eq_(len(mail.outbox), 4) ok_(mail.outbox[0].to[0] in recipients) ok_(mail.outbox[1].to[0] in recipients) @fudge.patch('remo.voting.models.celery_control.revoke') def test_send_email_on_edit_poll(self, fake_requests_obj): """Test sending emails when the poll is edited.""" Poll.objects.filter(pk=self.voting.id).update(task_start_id='1234', task_end_id='1234') poll = Poll.objects.get(pk=self.voting.id) poll.name = 'Edit Voting' if not settings.CELERY_ALWAYS_EAGER: (fake_requests_obj.expects_call().returns(True)) poll.save() eq_(len(mail.outbox), 6) def test_send_email_to_council_members(self): """Test send emails to Council Members if an automated poll is created. """ automated_poll = Poll(name='automated_poll', start=self.start, end=self.end, valid_groups=self.group, created_by=self.user, automated_poll=True) automated_poll.save() eq_(len(mail.outbox), 6) for email in mail.outbox: if settings.REPS_COUNCIL_ALIAS in email.to: break else: raise Exception('No email sent to REPS_COUNCIL_ALIAS')
def setUp(self): """Initial data for the tests.""" self.user = User.objects.get(username='******') self.group = Group.objects.get(name='Admin') self._now = datetime2pdt() self.now = self._now.replace(microsecond=0) self.start = self.now self.end = self.now + datetime.timedelta(days=5) self.voting = Poll(name='poll', start=self.start, end=self.end, valid_groups=self.group, created_by=self.user) self.voting.save()
def test_send_email_to_council_members(self): """Test send emails to Council Members if an automated poll is created. """ automated_poll = Poll(name='automated_poll', start=self.start, end=self.end, valid_groups=self.group, created_by=self.user, automated_poll=True) automated_poll.save() eq_(len(mail.outbox), 4) eq_(mail.outbox[2].to, [settings.REPS_COUNCIL_LIST]) eq_(mail.outbox[3].to, [settings.REPS_COUNCIL_LIST])
class VotingTestCommands(TestCase): """Test sending notifications.""" fixtures = ["demo_users.json"] def setUp(self): """Initial data for the tests.""" self.user = User.objects.get(username="******") self.group = Group.objects.get(name="Council") self._now = datetime2pdt() self.now = self._now.replace(microsecond=0) self.start = self.now self.end = self.now + datetime.timedelta(hours=5 * 24) self.voting = Poll(name="poll", start=self.start, end=self.end, valid_groups=self.group, created_by=self.user) self.voting.save() @patch("remo.voting.cron.datetime2pdt") def test_email_users_without_a_vote(self, fake_datetime2pdt): """Test sending an email to users who have not cast their vote yet. """ # act like it's today + 1 day fake_datetime2pdt.return_value = datetime2pdt() + datetime.timedelta(days=1) args = ["poll_vote_reminder"] management.call_command("cron", *args) eq_(len(mail.outbox), 3) for email in mail.outbox: eq_(email.to, ["*****@*****.**"]) @patch("remo.voting.cron.datetime2pdt") def test_extend_voting_period_by_24hours(self, fake_datetime2pdt): """Test extending voting period by 24hours if less than 50% of the valid users have voted and the poll ends in less than 8 hours. """ automated_poll = Poll( name="poll", start=self.start, end=self.end, valid_groups=self.group, created_by=self.user, automated_poll=True, ) automated_poll.save() # act like it's 4 hours before the end of the poll fake_datetime2pdt.return_value = datetime2pdt() + datetime.timedelta(hours=116) args = ["extend_voting_period"] management.call_command("cron", *args) poll = Poll.objects.get(pk=automated_poll.id) eq_(poll.end - automated_poll.end, datetime.timedelta(hours=24))
class VotingTestCommands(TestCase): """Test sending notifications.""" fixtures = ['demo_users.json'] def setUp(self): """Initial data for the tests.""" UserFactory.create(username='******', email='*****@*****.**', first_name='ReMo', last_name='bot') self.user = User.objects.get(username='******') self.group = Group.objects.get(name='Council') self._now = datetime2pdt() self.now = self._now.replace(microsecond=0) self.start = self.now self.end = self.now + datetime.timedelta(hours=5*24) self.voting = Poll(name='poll', start=self.start, end=self.end, valid_groups=self.group, created_by=self.user) self.voting.save() @patch('remo.voting.cron.datetime2pdt') def test_email_users_without_a_vote(self, fake_datetime2pdt): """Test sending an email to users who have not cast their vote yet. """ # act like it's today + 1 day fake_datetime2pdt.return_value = (datetime2pdt() + datetime.timedelta(days=1)) args = ['poll_vote_reminder'] management.call_command('cron', *args) recipients = map(lambda x: '%s' % x.email, User.objects.filter(groups=self.group)) eq_(len(mail.outbox), 3) eq_(mail.outbox[2].to, recipients) @patch('remo.voting.cron.datetime2pdt') def test_extend_voting_period_by_24hours(self, fake_datetime2pdt): """Test extending voting period by 24hours if less than 50% of the valid users have voted and the poll ends in less than 8 hours. """ automated_poll = Poll(name='poll', start=self.start, end=self.end, valid_groups=self.group, created_by=self.user, automated_poll=True) automated_poll.save() # act like it's 4 hours before the end of the poll fake_datetime2pdt.return_value = (datetime2pdt() + datetime.timedelta(hours=116)) args = ['extend_voting_period'] management.call_command('cron', *args) poll = Poll.objects.get(pk=automated_poll.id) eq_(poll.end - automated_poll.end, datetime.timedelta(hours=24))
def setUp(self): """Initial data for the tests.""" UserFactory.create(username='******', email='*****@*****.**', first_name='ReMo', last_name='bot') self.user = User.objects.get(username='******') self.group = Group.objects.get(name='Council') self._now = datetime2pdt() self.now = self._now.replace(microsecond=0) self.start = self.now self.end = self.now + datetime.timedelta(hours=5*24) self.voting = Poll(name='poll', start=self.start, end=self.end, valid_groups=self.group, created_by=self.user) self.voting.save()
class VotingTestCommands(TestCase): """Test sending notifications.""" fixtures = ['demo_users.json'] def setUp(self): """Initial data for the tests.""" self.user = User.objects.get(username='******') self.group = Group.objects.get(name='Council') self._now = now() self.now = self._now.replace(microsecond=0) self.start = self.now self.end = self.now + timedelta(hours=5*24) self.voting = Poll(name='poll', start=self.start, end=self.end, valid_groups=self.group, created_by=self.user) self.voting.save() @patch('remo.voting.cron.now') def test_email_users_without_a_vote(self, fake_now): """Test sending an email to users who have not cast their vote yet. """ # act like it's today + 1 day fake_now.return_value = now() + timedelta(days=1) args = ['poll_vote_reminder'] management.call_command('cron', *args) eq_(len(mail.outbox), 3) eq_(mail.outbox[0].to, [u'*****@*****.**']) eq_(mail.outbox[1].to, [u'*****@*****.**']) eq_(mail.outbox[2].to, [u'Babis Sougias <*****@*****.**>']) @patch('remo.voting.cron.EXTEND_VOTING_PERIOD', 24 * 3600) def test_extend_voting_period(self): bug = BugFactory.create() end = get_date(days=1) new_end = get_date(days=2) automated_poll = Poll(name='poll', start=self.start, end=end, valid_groups=self.group, created_by=self.user, automated_poll=True, bug=bug) automated_poll.save() args = ['extend_voting_period'] management.call_command('cron', *args) 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)
def test_send_email_to_council_members(self): """Test send emails to Council Members if an automated poll is created. """ automated_poll = Poll(name='automated_poll', start=self.start, end=self.end, valid_groups=self.group, created_by=self.user, automated_poll=True) automated_poll.save() eq_(len(mail.outbox), 4) for email in mail.outbox: if settings.REPS_COUNCIL_ALIAS in email.to: break else: raise Exception('No email sent to REPS_COUNCIL_ALIAS')
class VotingMailNotificationTest(TestCase): """Tests related to Voting Models.""" fixtures = ['demo_users.json'] def setUp(self): """Initial data for the tests.""" self.user = User.objects.get(username='******') self.group = Group.objects.get(name='Admin') self._now = now() self.now = self._now.replace(microsecond=0) self.start = self.now self.end = self.now + datetime.timedelta(days=5) self.voting = Poll(name='poll', start=self.start, end=self.end, valid_groups=self.group, created_by=self.user) self.voting.save() def test_send_email_on_save_poll(self): """Test sending emails when a new voting is added.""" recipients = map(lambda x: '%s' % x.email, User.objects.filter(groups=self.group)) eq_(len(mail.outbox), 2) ok_(mail.outbox[0].to[0] in recipients) ok_(mail.outbox[1].to[0] in recipients) @fudge.patch('remo.voting.models.celery_control.revoke') def test_send_email_on_edit_poll(self, fake_requests_obj): """Test sending emails when the poll is edited.""" Poll.objects.filter(pk=self.voting.id).update(task_start_id='1234', task_end_id='1234') poll = Poll.objects.get(pk=self.voting.id) poll.name = 'Edit Voting' if not settings.CELERY_ALWAYS_EAGER: (fake_requests_obj.expects_call().returns(True)) poll.save() eq_(len(mail.outbox), 3) def test_send_email_to_council_members(self): """Test send emails to Council Members if an automated poll is created. """ automated_poll = Poll(name='automated_poll', start=self.start, end=self.end, valid_groups=self.group, created_by=self.user, automated_poll=True) automated_poll.save() eq_(len(mail.outbox), 4) for email in mail.outbox: if settings.REPS_COUNCIL_ALIAS in email.to: break else: raise Exception('No email sent to REPS_COUNCIL_ALIAS')
class VotingTestCommands(TestCase): """Test sending notifications.""" fixtures = ['demo_users.json'] def setUp(self): """Initial data for the tests.""" self.user = User.objects.get(username='******') self.group = Group.objects.get(name='Council') self._now = now() self.now = self._now.replace(microsecond=0) self.start = self.now self.end = self.now + datetime.timedelta(hours=5*24) self.voting = Poll(name='poll', start=self.start, end=self.end, valid_groups=self.group, created_by=self.user) self.voting.save() @patch('remo.voting.cron.now') def test_email_users_without_a_vote(self, fake_now): """Test sending an email to users who have not cast their vote yet. """ # act like it's today + 1 day fake_now.return_value = now() + datetime.timedelta(days=1) args = ['poll_vote_reminder'] management.call_command('cron', *args) eq_(len(mail.outbox), 3) eq_(mail.outbox[0].to, [u'*****@*****.**']) eq_(mail.outbox[1].to, [u'*****@*****.**']) eq_(mail.outbox[2].to, [u'Babis Sougias <*****@*****.**>']) @patch('remo.voting.cron.now') def test_extend_voting_period_by_24hours(self, fake_now): """Test extending voting period by 24hours if less than 50% of the valid users have voted and the poll ends in less than 8 hours. """ bug = BugFactory.create() automated_poll = Poll(name='poll', start=self.start, end=self.end, valid_groups=self.group, created_by=self.user, automated_poll=True, bug=bug) automated_poll.save() # act like it's 4 hours before the end of the poll fake_now.return_value = now() + datetime.timedelta(hours=116) args = ['extend_voting_period'] management.call_command('cron', *args) poll = Poll.objects.get(pk=automated_poll.id) eq_(poll.end - automated_poll.end, datetime.timedelta(hours=24))
def setUp(self): """Initial data for the tests.""" self.user = User.objects.get(username='******') self.group = Group.objects.get(name='Admin') self._now = timezone.make_aware(datetime.datetime.now(), pytz.timezone(settings.TIME_ZONE)) self.now = self._now.replace(microsecond=0) self.start = self.now self.end = self.now + datetime.timedelta(days=5) self.voting = Poll(name='poll', start=self.start, end=self.end, valid_groups=self.group, created_by=self.user) self.voting.save()
def test_extend_voting_period_by_24hours(self, fake_now): """Test extending voting period by 24hours if less than 50% of the valid users have voted and the poll ends in less than 8 hours. """ automated_poll = Poll(name='poll', start=self.start, end=self.end, valid_groups=self.group, created_by=self.user, automated_poll=True) automated_poll.save() # act like it's 4 hours before the end of the poll fake_now.return_value = now() + datetime.timedelta(hours=116) args = ['extend_voting_period'] management.call_command('cron', *args) poll = Poll.objects.get(pk=automated_poll.id) eq_(poll.end - automated_poll.end, datetime.timedelta(hours=24))
def test_extend_voting_period_by_24hours(self, fake_datetime2pdt): """Test extending voting period by 24hours if less than 50% of the valid users have voted and the poll ends in less than 8 hours. """ automated_poll = Poll(name='poll', start=self.start, end=self.end, valid_groups=self.group, created_by=self.user, automated_poll=True) automated_poll.save() # act like it's 4 hours before the end of the poll fake_datetime2pdt.return_value = (datetime2pdt() + datetime.timedelta(hours=116)) args = ['extend_voting_period'] management.call_command('cron', *args) poll = Poll.objects.get(pk=automated_poll.id) eq_(poll.end - automated_poll.end, datetime.timedelta(hours=24))
def setUp(self): """Initial data for the tests.""" self.user = User.objects.get(username="******") self.group = Group.objects.get(name="Council") self._now = datetime2pdt() self.now = self._now.replace(microsecond=0) self.start = self.now self.end = self.now + datetime.timedelta(hours=5 * 24) self.voting = Poll(name="poll", start=self.start, end=self.end, valid_groups=self.group, created_by=self.user) self.voting.save()
def test_extend_voting_period(self): bug = BugFactory.create() end = get_date(days=1) new_end = get_date(days=2) automated_poll = Poll(name='poll', start=self.start, end=end, valid_groups=self.group, created_by=self.user, automated_poll=True, bug=bug) automated_poll.save() args = ['extend_voting_period'] management.call_command('cron', *args) 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)
def setUp(self): """Initial data for the tests.""" self.user = User.objects.get(username='******') self.group = Group.objects.get(name='Admin') self._now = now() self.now = self._now.replace(microsecond=0) self.start = self.now self.end = self.now + datetime.timedelta(days=5) self.voting = Poll(name='poll', start=self.start, end=self.end, valid_groups=self.group, created_by=self.user) self.voting.save()