'Test limit and offset in conjunction with both orm and fn filtering.'

def test_list(self):

    user2 = self.user_manager.create(**user2_data)
    history1 = self.history_manager.create(name='history1', user=user2)
    history2 = self.history_manager.create(name='history2', user=user2)
    history3 = self.history_manager.create(name='history3', user=user2)
    history4 = self.history_manager.create(name='history4', user=user2)
    self.history_manager.delete(history1)
    self.history_manager.delete(history2)
    self.history_manager.delete(history3)
    test_annotation = 'testing'
    history2.add_item_annotation(self.trans.sa_session, user2, history2, test_annotation)
    self.trans.sa_session.flush()
    history3.add_item_annotation(self.trans.sa_session, user2, history3, test_annotation)
    self.trans.sa_session.flush()
    history3.add_item_annotation(self.trans.sa_session, user2, history4, test_annotation)
    self.trans.sa_session.flush()
    all_histories = [history1, history2, history3, history4]
    deleted_and_annotated = [history2, history3]
    self.log('no    offset,    no    limit    should    work')
    self.assertEqual(self.history_manager.list(offset=None, limit=None), all_histories)
    self.assertEqual(self.history_manager.list(), all_histories)
    self.log('no    offset,    limit    should    work')
    self.assertEqual(self.history_manager.list(limit=2), [history1, history2])
    self.log('offset,    no    limit    should    work')
    self.assertEqual(self.history_manager.list(offset=1), [history2, history3, history4])
    self.log('offset,    limit    should    work')
    self.assertEqual(self.history_manager.list(offset=1, limit=1), [history2])
    self.log('zero    limit    should    return    empty    list')
    self.assertEqual(self.history_manager.list(limit=0), [])
    self.log('past    len    offset    should    return    empty    list')
    self.assertEqual(self.history_manager.list(offset=len(all_histories)), [])
    self.log('negative    limit    should    return    full    list')
    self.assertEqual(self.history_manager.list(limit=(-1)), all_histories)
    self.log('negative    offset    should    return    full    list')
    self.assertEqual(self.history_manager.list(offset=(-1)), all_histories)
    filters = [(model.History.deleted == true())]
    self.log('orm    filtered,    no    offset,    no    limit    should    work')
    found = self.history_manager.list(filters=filters)
    self.assertEqual(found, [history1, history2, history3])
    self.log('orm    filtered,    no    offset,    limit    should    work')
    found = self.history_manager.list(filters=filters, limit=2)
    self.assertEqual(found, [history1, history2])
    self.log('orm    filtered,    offset,    no    limit    should    work')
    found = self.history_manager.list(filters=filters, offset=1)
    self.assertEqual(found, [history2, history3])
    self.log('orm    filtered,    offset,    limit    should    work')
    found = self.history_manager.list(filters=filters, offset=1, limit=1)
    self.assertEqual(found, [history2])
    filters = self.filter_parser.parse_filters([('annotation', 'has', test_annotation)])
    self.log('fn    filtered,    no    offset,    no    limit    should    work')
    found = self.history_manager.list(filters=filters)
    self.assertEqual(found, [history2, history3, history4])
    self.log('fn    filtered,    no    offset,    limit    should    work')
    found = self.history_manager.list(filters=filters, limit=2)
    self.assertEqual(found, [history2, history3])
    self.log('fn    filtered,    offset,    no    limit    should    work')
    found = self.history_manager.list(filters=filters, offset=1)
    self.assertEqual(found, [history3, history4])
    self.log('fn    filtered,    offset,    limit    should    work')
    found = self.history_manager.list(filters=filters, offset=1, limit=1)
    self.assertEqual(found, [history3])
    filters = self.filter_parser.parse_filters([('deleted', 'eq', 'True'), ('annotation', 'has', test_annotation)])
    self.log('orm    and    fn    filtered,    no    offset,    no    limit    should    work')
    found = self.history_manager.list(filters=filters)
    self.assertEqual(found, [history2, history3])
    self.log('orm    and    fn    filtered,    no    offset,    limit    should    work')
    found = self.history_manager.list(filters=filters, limit=1)
    self.assertEqual(found, [history2])
    self.log('orm    and    fn    filtered,    offset,    no    limit    should    work')
    found = self.history_manager.list(filters=filters, offset=1)
    self.assertEqual(found, [history3])
    self.log('orm    and    fn    filtered,    offset,    limit    should    work')
    found = self.history_manager.list(filters=filters, offset=1, limit=1)
    self.assertEqual(found, [history3])
    self.log('orm    and    fn    filtered,    zero    limit    should    return    empty    list')
    found = self.history_manager.list(filters=filters, limit=0)
    self.assertEqual(found, [])
    self.log('orm    and    fn    filtered,    past    len    offset    should    return    empty    list')
    found = self.history_manager.list(filters=filters, offset=len(deleted_and_annotated))
    self.assertEqual(found, [])
    self.log('orm    and    fn    filtered,    negative    limit    should    return    full    list')
    found = self.history_manager.list(filters=filters, limit=(-1))
    self.assertEqual(found, deleted_and_annotated)
    self.log('orm    and    fn    filtered,    negative    offset    should    return    full    list')
    found = self.history_manager.list(filters=filters, offset=(-1))
    self.assertEqual(found, deleted_and_annotated)
