<commit_before>import datetime
import pytz

from django.contrib.auth.models import Group, User
from django.core import mail, management
from django.utils import timezone

import fudge

from nose.tools import eq_
from test_utils import TestCase

from remo.voting.models import Poll


class VotingTestCommands(TestCase):
    """Test sending notifications."""
    fixtures = ['demo_users.json']

    def setUp(self):
        """Initial data for the tests."""
        self.user = User.objects.get(username='admin')
        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.

        """
        today = datetime.datetime.today()

        # act like it's today + 1 day
        fake_date = datetime.datetime(year=today.year, month=today.month,
                                      day=today.day + 1, hour=today.hour,
                                      minute=today.minute)
        (fake_requests_obj.expects_call().returns(fake_date))
        args = ['poll_vote_reminder']
        management.call_command('cron', *args)
        eq_(len(mail.outbox), 3)<commit_msg>[fix bug 899941] Fix mocked date in voting tests.<commit_after>import datetime
import pytz

from django.contrib.auth.models import Group, User
from django.core import mail, management
from django.utils import timezone

import fudge

from nose.tools import eq_
from test_utils import TestCase

from remo.voting.models import Poll


class VotingTestCommands(TestCase):
    """Test sending notifications."""
    fixtures = ['demo_users.json']

    def setUp(self):
        """Initial data for the tests."""
        self.user = User.objects.get(username='admin')
        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)
{'fraction_non_alphanumeric': 0.11237016052880075, 'fraction_numerical': 0.005036197670758577, 'mean_word_length': 2.7968936678614096, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2628812', 'n_tokens_mistral': 973, 'n_tokens_neox': 942, 'n_words': 213}