'Scheduled queries that fail have their failure recorded.'

def test_failure_scheduled(self):

    cm = mock.patch('celery.app.task.Context.delivery_info', {'routing_key': 'test'})
    q = self.factory.create_query(query_text='SELECT    1,    2', schedule=300)
    with cm:
        with mock.patch.object(PostgreSQL, 'run_query') as qr:
            qr.exception = ValueError('broken')
            execute_query('SELECT    1,    2', self.factory.data_source.id, {}, scheduled_query_id=q.id)
            self.assertEqual(q.schedule_failures, 1)
            execute_query('SELECT    1,    2', self.factory.data_source.id, {}, scheduled_query_id=q.id)
            q = models.Query.get_by_id(q.id)
            self.assertEqual(q.schedule_failures, 2)
