def test_get_frequency_if_not(self): # setup task = Task(Mock()) # asserts with self.assertRaises(NotImplementedError): task.get_frequency()
def test_get_frequency_if(self): # setup task = Task(Mock()) task.frequency = 5 # asserts self.assertEqual(task.get_frequency(), 5)
def test_run(self): # setup task = Task(Mock()) # asserts with self.assertRaises(NotImplementedError): task.run()
def test_get_name_if(self): # setup task = Task(Mock()) task.name = "name" # asserts self.assertEqual(task.get_name(), "name")
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()
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)
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)