예제 #1
0
    def test_get_frequency_if_not(self):
        # setup
        task = Task(Mock())

        # asserts
        with self.assertRaises(NotImplementedError):
            task.get_frequency()
예제 #2
0
    def test_get_frequency_if(self):
        # setup
        task = Task(Mock())
        task.frequency = 5

        # asserts
        self.assertEqual(task.get_frequency(), 5)
예제 #3
0
    def test_run(self):
        # setup
        task = Task(Mock())

        # asserts
        with self.assertRaises(NotImplementedError):
            task.run()
예제 #4
0
    def test_get_name_if(self):
        # setup
        task = Task(Mock())
        task.name = "name"

        # asserts
        self.assertEqual(task.get_name(), "name")
예제 #5
0
    def test_full_run_if_not_run_again(self, mock_run, mock_get_instance):
        # setup
        mock_get_instance.return_value = Mock(
            run_again=Mock(return_value=False)
        )

        task = Task(Mock())
        task.full_run()

        # asserts
        mock_run.assert_not_called()
예제 #6
0
    def test_get_instance_created(self):
        # setup
        task = Task(Mock())
        task.name = "Test Name"
        task.frequency = 5

        task_instance = task.get_instance()
        tasks = TaskModel.objects.all()

        # asserts
        self.assertEqual(tasks.count(), 1)
        self.assertEqual(tasks.first(), task_instance)
        self.assertEqual(task_instance.name, "Test Name")
        self.assertEqual(task_instance.frequency, 5)
예제 #7
0
    def test_full_run_if_run_again(self, mock_run, mock_get_instance,
                                   MockTaskRun):
        # setup
        instance = Mock(
            run_again=Mock(return_value=True)
        )
        mock_get_instance.return_value = instance

        task = Task(Mock())
        task.name = "Test Name"
        task.full_run()

        # asserts
        mock_run.assert_called_once()
        MockTaskRun.objects.create.assert_called_once_with(task=instance)