def test_update_next_run_at_cron(self):
        """Test that next_run_at = croniter parse."""
        self.install_fixture('pipeline_schedule_cron')

        # Set last_run_at to expected
        PipelineScheduleService.update_last_run_at_for_pipeline(
            self.pipeline.id,
        )

        # Update next_run_at
        PipelineScheduleService.update_next_run_at_for_pipeline(
            self.pipeline.id,
        )

        # Assert that next_run_at is expected
        self._assert_pipeline_attribute_equals(
            self.pipeline.id,
            'next_run_at',
            datetime(2014, 2, 1, 0, 5),
        )
    def test_update_next_run_at_manual(self):
        """Test that next_run_at = none."""
        self.install_fixture('pipeline_schedule_manual')

        # Update last_run_at
        PipelineScheduleService.update_last_run_at_for_pipeline(
            self.pipeline.id,
        )

        # Update next_run_at
        PipelineScheduleService.update_next_run_at_for_pipeline(
            self.pipeline.id,
        )

        # Assert next_run_at is updated to None
        self._assert_pipeline_attribute_equals(
            self.pipeline.id,
            'next_run_at',
            None,
        )
    def test_update_last_run_at(self):
        """Test that last_run_at is updated to the latest date."""
        self.install_fixture('pipeline_schedule_interval')

        # Assert that last_run_at is empty
        self._assert_pipeline_attribute_equals(
            self.pipeline.id,
            'last_run_at',
            None,
        )

        # Set last_run_at to expected
        PipelineScheduleService.update_last_run_at_for_pipeline(
            self.pipeline.id,
        )

        # Assert that last_run_at is expected
        self._assert_pipeline_attribute_equals(
            self.pipeline.id,
            'last_run_at',
            datetime(2014, 02, 01),
        )
    def test_update_next_run_at_interval(self):
        """Test that next_run_at = last_run_at + interval."""
        self.install_fixture('pipeline_schedule_interval')

        # Update last_run_at
        PipelineScheduleService.update_last_run_at_for_pipeline(
            self.pipeline.id,
        )

        # Update next_run_at
        PipelineScheduleService.update_next_run_at_for_pipeline(
            self.pipeline.id,
        )

        # Assert next_run_at is updated to last_run_at + interval
        schedule = PipelineScheduleService.fetch_schedule_for_pipeline(
            self.pipeline.id,
        )

        self._assert_pipeline_attribute_equals(
            self.pipeline.id,
            'next_run_at',
            schedule.last_run_at + timedelta(seconds=int(schedule.schedule)),
        )