<commit_before>"""
Unittests for the rm.trials.tasks module
"""
import sys
import unittest

from mock import MagicMock, patch

if sys.version_info <  (2, 7): import unittest2 as unittest

from rm import exceptions
from rm.trials import tasks

class EmailSingleInstructionsTestCase(unittest.TestCase):
    def setUp(self):
        pass

    def tearDown(self):
        pass

    def test_fetches_active(self):
        "Make sure we fetch the active trials"
        mock_trial = MagicMock(name="Mock Single User Trial")
        with patch.object(tasks.models.SingleUserTrial.objects, 'active') as pact:
            pact.return_value = [mock_trial]
            tasks.email_single_instructions()
            pact.assert_called_once_with()
            mock_trial.send_instructions.assert_called_once_with()

    def test_no_email(self):
        "If a user has no email, continue."
        def raiser():
            raise exceptions.NoEmailError()

        mock_trial1 = MagicMock(name="Mock Single User Trial 1")
        mock_trial1.send_instructions.side_effect = raiser
        mock_trial2 = MagicMock(name="Mock Single User Trial 2")
        with patch.object(tasks.models.SingleUserTrial.objects, 'active') as pact:
            pact.return_value = [mock_trial1, mock_trial2]
            tasks.email_single_instructions()
            mock_trial2.send_instructions.assert_called_once_with()


class EmailRmInstructionsTestCase(unittest.TestCase):
    def setUp(self):
        pass

    def tearDown(self):
        pass

    def test_fetches_active(self):
        "Make sure we fetch the active trials"
        mock_trial = MagicMock(name="Mock Rm User Trial")
        with patch.object(tasks.models.Trial.objects, 'starting_today') as ptod:
            ptod.return_value = [mock_trial]
            tasks.email_rm_instructions()
            ptod.assert_called_once_with()
            mock_trial.randomise.assert_called_once_with()
            mock_trial.send_instructions.assert_called_once_with()



if __name__ == '__main__':
    unittest.main()
<commit_msg>Fix failing tests - depreciated data model.<commit_after>"""
Unittests for the rm.trials.tasks module
"""
import sys
import unittest

from mock import MagicMock, patch

if sys.version_info <  (2, 7): import unittest2 as unittest

from rm import exceptions
from rm.trials import tasks

class EmailRmInstructionsTestCase(unittest.TestCase):
    def setUp(self):
        pass

    def tearDown(self):
        pass

    def test_fetches_active(self):
        "Make sure we fetch the active trials"
        mock_trial = MagicMock(name="Mock Rm User Trial")
        with patch.object(tasks.models.Trial.objects, 'starting_today') as ptod:
            ptod.return_value = [mock_trial]
            tasks.email_rm_instructions()
            ptod.assert_called_once_with()
            mock_trial.randomise.assert_called_once_with()
            mock_trial.send_instructions.assert_called_once_with()



if __name__ == '__main__':
    unittest.main()

{'fraction_non_alphanumeric': 0.08313856427378966, 'fraction_numerical': 0.004674457429048414, 'mean_word_length': 3.0268817204301075, 'pattern_counts': {'":': 0, '<': 5, '<?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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2107151', 'n_tokens_mistral': 925, 'n_tokens_neox': 870, 'n_words': 210}