예제 #1
0
    def test_run_task(self):
        task = self.tasks["fetch_source_b"]
        with mock.patch("pipeline.runner.call_command"):
            run_task(task, 2017, 7)

        log = TaskLog.objects.get(year=2017,
                                  month=7,
                                  task_name="fetch_source_b")
        self.assertEqual(log.status, "successful")
        self.assertIsNotNone(log.ended_at)
예제 #2
0
    def test_run_task_after_success(self):
        task = self.tasks['fetch_source_b']
        with mock.patch('pipeline.runner.call_command') as cc:
            run_task(task, 2017, 7)

        with mock.patch('pipeline.runner.call_command') as cc:
            run_task(task, 2017, 7)
            cc.assert_not_called()

        logs = TaskLog.objects.filter(year=2017,
                                      month=7,
                                      task_name='fetch_source_b')
        self.assertEqual(1, logs.count())
예제 #3
0
    def test_run_task_that_fails(self):
        task = self.tasks["fetch_source_b"]
        with self.assertRaises(KeyboardInterrupt):
            with mock.patch("pipeline.runner.call_command") as cc:
                cc.side_effect = KeyboardInterrupt
                run_task(task, 2017, 7)

        log = TaskLog.objects.get(year=2017,
                                  month=7,
                                  task_name="fetch_source_b")
        self.assertEqual(log.status, "failed")
        self.assertIsNotNone(log.ended_at)
        self.assertIn("KeyboardInterrupt", log.formatted_tb)
예제 #4
0
    def test_run_task_after_failure(self):
        task = self.tasks['fetch_source_b']
        with self.assertRaises(KeyboardInterrupt):
            with mock.patch('pipeline.runner.call_command') as cc:
                cc.side_effect = KeyboardInterrupt
                run_task(task, 2017, 7)

        with mock.patch('pipeline.runner.call_command') as cc:
            run_task(task, 2017, 7)

        logs = TaskLog.objects.filter(year=2017,
                                      month=7,
                                      task_name='fetch_source_b')
        self.assertEqual(2, logs.count())