def test_bookmarks(): def twoway(x): before = x ss = serialize_bookmark(x) after = unserialize_bookmark(ss) return before == after first = (None, False) last = (None, True) assert serialize_bookmark(first) == ">" assert serialize_bookmark(last) == "<" assert twoway(first) assert twoway(last)
def general_asserts(p): if not p.backwards: assert p.further == p.next else: assert p.further == p.previous if not p.has_further: assert p.current_opposite == (None, not p.backwards) assert p.is_full == (len(p.rows) >= p.per_page) assert p.bookmark_further == serialize_bookmark(p.further)
def check_paging(q=None, selectable=None, s=None): ITEM_COUNTS = range(1, 12) if q is not None: unpaged = q.all() elif selectable is not None: result = s.execute(selectable) unpaged = result.fetchall() for per_page in ITEM_COUNTS: for backwards in [False, True]: gathered = [] page = None, backwards while True: serialized_page = serialize_bookmark(page) page = unserialize_bookmark(serialized_page) if q is not None: method = get_page args = (q, ) elif selectable is not None: method = select_page args = (s, selectable) rows = method(*args, per_page=per_page, page=serialized_page) p = rows.paging assert p.current == page if selectable is not None: assert rows.keys() == result.keys() if backwards: gathered = rows + gathered else: gathered = gathered + rows page = p.further if not rows: assert not p.has_further assert p.further == p.current assert p.current_opposite == (None, not p.backwards) break assert gathered == unpaged
def check_paging_orm(q): item_counts = range(1, 12) unpaged = q.all() for backwards in [False, True]: for per_page in item_counts: gathered = [] page = None, backwards while True: serialized_page = serialize_bookmark(page) page = unserialize_bookmark(serialized_page) page_with_paging = get_page(q, per_page=per_page, page=serialized_page) paging = page_with_paging.paging assert paging.current == page if backwards: gathered = page_with_paging + gathered else: gathered = gathered + page_with_paging page = paging.further if len(gathered) < len(unpaged): # Ensure each page is the correct size assert paging.has_further assert len(page_with_paging) == per_page else: assert not paging.has_further if not page_with_paging: assert not paging.has_further assert paging.further == paging.current assert paging.current_opposite == (None, not paging.backwards) break # Ensure union of pages is original q.all() assert gathered == unpaged
def check_paging_core(selectable, s): item_counts = range(1, 12) result = s.execute(selectable) unpaged = result.fetchall() for backwards in [False, True]: for per_page in item_counts: gathered = [] page = None, backwards while True: serialized_page = serialize_bookmark(page) page = unserialize_bookmark(serialized_page) page_with_paging = select_page(s, selectable, per_page=per_page, page=serialized_page) paging = page_with_paging.paging assert paging.current == page assert page_with_paging.keys() == result.keys() if backwards: gathered = page_with_paging + gathered else: gathered = gathered + page_with_paging page = paging.further if not page_with_paging: assert not paging.has_further assert paging.further == paging.current assert paging.current_opposite == (None, not paging.backwards) break assert gathered == unpaged
def check_paging_orm(q): item_counts = range(1, 12) unpaged = q.all() for backwards in [False, True]: for per_page in item_counts: gathered = [] page = None, backwards while True: serialized_page = serialize_bookmark(page) page = unserialize_bookmark(serialized_page) page_with_paging = get_page(q, per_page=per_page, page=serialized_page) paging = page_with_paging.paging assert paging.current == page if backwards: gathered = page_with_paging + gathered else: gathered = gathered + page_with_paging page = paging.further if not page_with_paging: assert not paging.has_further assert paging.further == paging.current assert paging.current_opposite == (None, not paging.backwards) break assert gathered == unpaged
def twoway(x): before = x ss = serialize_bookmark(x) after = unserialize_bookmark(ss) return before == after