Пример #1
0
 def test_next_at_end_4pp(self):
     p = Pager(self.db.view, '%s/all'%model_type)
     # Check that using prev again doesn't break
     prev, rows, next, stats = t(p.get(4, None))
     prev, rows, next, stats = t(p.get(4, next))
     prev, rows, next, stats = t(p.get(4, next))
     assert_page(1, prev, rows, next, stats, e4pp_5t)
Пример #2
0
 def test_next_at_end_6pp(self):
     p = Pager(self.db.view, '%s/all'%model_type)
     # Go forward and back the whole way, 5 per page
     prev, rows, next, stats = t(p.get(6, None))
     assert_page(1, prev, rows, next, stats, e6pp_5t)
     prev, rows, next, stats = t(p.get(6, next))
     assert_page(1, prev, rows, next, stats, e6pp_5t)
Пример #3
0
 def test_jumpref_pageback(self):
     self.db['_design/test'] = {'views': {'test': {'map': 'function(doc) {emit(doc.letter, null);}'}}}
     self.db.update([{'letter': 'a'} for i in range(100)])
     self.db.update([{'letter': 'b'} for i in range(100)])
     pager = Pager(self.db.view, 'test/test')
     prev, items, next, stats = t(pager.get(5, Pager.jumpref('b')))
     assert items[0].key == 'b'
Пример #4
0
 def test_jumpref_start(self):
     self.db['_design/test'] = {'views': {'test': {'map': 'function(doc) {emit(doc.letter+doc.letter, null);}'}}}
     self.db.update([{'letter': letter} for letter in 'abcdefghijklmnopqrstuvwxyz'])
     pager = Pager(self.db.view, 'test/test')
     prev, items, next, stats = t(pager.get(5, Pager.jumpref('a')))
     assert items[0].key == 'aa'
     prev, items, next, stats = t(pager.get(5, Pager.jumpref('aa')))
     assert items[0].key == 'aa'
Пример #5
0
 def test_roundtrip_5pp(self):
     p = Pager(self.db.view, '%s/all'%model_type)
     # Go forward and back the whole way, 5 per page
     prev, rows, next, stats = t(p.get(5, None))
     assert_page(1,prev, rows, next, stats, e5pp_10t)
     prev, rows, next, stats = t(p.get(5, next))
     assert_page(2,prev, rows, next, stats, e5pp_10t)
     prev, rows, next, stats = t(p.get(5, prev))
     assert_page(1,prev, rows, next, stats, e5pp_10t)
Пример #6
0
 def test_roundtrip_5pp_reversed(self):
     p = Pager(self.db.view, '%s/all'%model_type, dict(startkey=14, endkey=5, descending=True))
     expecteds = [ [14,13,12,11,10],[9,8,7,6,5] ]
     prev, rows, next, stats = t(p.get(5, None))
     assert_page(1,prev, rows, next, stats, expecteds)
     prev, rows, next, stats = t(p.get(5, next))
     assert_page(2,prev, rows, next, stats, expecteds)
     prev, rows, next, stats = t(p.get(5, prev))
     assert_page(1,prev, rows, next, stats, expecteds)
Пример #7
0
 def test_roundtrip_5pp(self):
     p = Pager(self.db.view, '%s/all'%model_type, dict(startkey=5, endkey=14))
     expecteds = [ [5,6,7,8,9],[10,11,12,13,14] ]
     prev, rows, next, stats = t(p.get(5, None))
     assert_page(1,prev, rows, next, stats, expecteds)
     prev, rows, next, stats = t(p.get(5, next))
     assert_page(2,prev, rows, next, stats, expecteds)
     prev, rows, next, stats = t(p.get(5, prev))
     assert_page(1,prev, rows, next, stats, expecteds)
Пример #8
0
 def test_remove_prevref(self):
     e5pp_15t_before = [ [0,1,2,3,4], [5,6,7,8,9], [10,11,12,13,14] ]
     e5pp_15t_after = [ [0,1,2,3], [5,6,7,8,9], [10,11,12,13,14] ]
     p = Pager(self.db.view, '%s/all'%model_type)
     prev, rows, next, stats = t(p.get(5, None))
     assert_page(1, prev, rows, next, stats, e5pp_15t_before)
     del self.db['id-4']
     prev, rows, next, stats = t(p.get(5, next))
     assert_page(2, prev, rows, next, stats, e5pp_15t_after)
Пример #9
0
 def test_remove_prevref_reverse(self):
     e5pp_10t_before = [ [9,8,7,6,5], [4,3,2,1,0] ]
     e5pp_10t_after = [ [9,8,7,6], [4,3,2,1,0] ]
     p = Pager(self.db.view, '%s/all'%model_type, dict(descending=True))
     prev, rows, next, stats = t(p.get(5, None))
     assert_page(1, prev, rows, next, stats, e5pp_10t_before)
     del self.db['id-5']
     prev, rows, next, stats = t(p.get(5, next))
     assert_page(2, prev, rows, next, stats, e5pp_10t_after)
Пример #10
0
 def test_upone_downone_4pp(self):
     p = Pager(self.db.view, '%s/all'%model_type)
     # got forward and back one page, 4 per page
     prev, rows, next, stats = t(p.get(4, None))
     assert_page(1, prev, rows, next, stats, e4pp_10t)
     prev, rows, next, stats = t(p.get(4, next))
     assert_page(2, prev, rows, next, stats, e4pp_10t)
     prev, rows, next, stats = t(p.get(4, prev))
     assert_page(1, prev, rows, next, stats, e4pp_10t)
Пример #11
0
 def test_remove_alldata_reversed(self):
     e5pp_10t_before = [ [9,8,7,6,5], [4,3,2,1,0] ]
     e5pp_10t_after = [ [] ]
     p = Pager(self.db.view, '%s/all'%model_type, dict(descending=True))
     prev, rows, next, stats = t(p.get(5, None))
     assert_page(1, prev, rows, next, stats, e5pp_10t_before)
     for i in xrange(0,10):
         del self.db['id-%s'%i]
     prev, rows, next, stats = t(p.get(5, next))
     assert_page(2, prev, rows, next, stats, e5pp_10t_after)
Пример #12
0
 def test_remove_alldata(self):
     e5pp_10t_before = [ [0,1,2,3,4], [5,6,7,8,9] ]
     e5pp_10t_after = [ [] ]
     p = Pager(self.db.view, '%s/all'%model_type)
     prev, rows, next, stats = t(p.get(5, None))
     assert_page(1, prev, rows, next, stats, e5pp_10t_before)
     for i in xrange(0,10):
         del self.db['id-%s'%i]
     prev, rows, next, stats = t(p.get(5, next))
     assert_page(2, prev, rows, next, stats, e5pp_10t_after)
     prev, rows, next, stats = t(p.get(5, prev))
     assert_page(1, prev, rows, next, stats, e5pp_10t_after)
Пример #13
0
 def test_prev_at_start_4pp(self):
     p = Pager(self.db.view, '%s/all'%model_type)
     # got forward and back one page, 4 per page
     prev, rows, next, stats = t(p.get(4, None))
     assert_page(1, prev, rows, next, stats, e4pp_10t)
     prev, rows, next, stats = t(p.get(4, next))
     assert_page(2, prev, rows, next, stats, e4pp_10t)
     prev, rows, next, stats = t(p.get(4, prev))
     assert_page(1, prev, rows, next, stats, e4pp_10t)
     # Check that using prev again doesn't break
     prev, rows, next, stats = t(p.get(4, prev))
     assert_page(1, prev, rows, next, stats, e4pp_10t)
Пример #14
0
 def test_remove_lots(self):
     e5pp_15t_before = [ [2,3,4,5,6], [7,8,9,10,11], [12] ]
     e5pp_15t_after = [ [2,3,4,5], [] ]
     e5pp_15t_after_secondpass = [ [2,3,4,5] ]
     p = Pager(self.db.view, '%s/all'%model_type, dict(startkey=2, endkey=12))
     prev, rows, next, stats = t(p.get(5, None))
     assert_page(1, prev, rows, next, stats, e5pp_15t_before)
     for i in xrange(6,13):
         del self.db['id-%s'%i]
     prev, rows, next, stats = t(p.get(5, next))
     assert_page(2, prev, rows, next, stats, e5pp_15t_after)
     prev, rows, next, stats = t(p.get(5, prev))
     assert_page(1, prev, rows, next, stats, e5pp_15t_after_secondpass)
     prev, rows, next, stats = t(p.get(5, next))
     assert_page(1, prev, rows, next, stats, e5pp_15t_after_secondpass)
Пример #15
0
    def test_remove_lots_trigger_hack_and_revscan2(self):
        e5pp_15t_before = [ [2,3,4,5,6], [7,8,9,10,11], [12] ]
        e5pp_15t_after1 = [ [2,3,4,5,6], [7,8,9,10,11], [] ]
        e5pp_15t_after2 = [ [2,3,4,5], [7,8,9,10,11] ]
        e5pp_15t_after_secondpass = [ [], [7,8,9,10,11] ]
        p = Pager(self.db.view, '%s/all'%model_type, dict(startkey=2, endkey=12))
        prev, rows, next, stats = t(p.get(5, None))
        assert_page(1, prev, rows, next, stats, e5pp_15t_before)

        prev, rows, next, stats = t(p.get(5, next))
        assert_page(2, prev, rows, next, stats, e5pp_15t_before)

        del self.db['id-12']
        prev, rows, next, stats = t(p.get(5, next))
        assert_page(3, prev, rows, next, stats, e5pp_15t_after1)

        del self.db['id-6']
        prev, rows, next, stats = t(p.get(5, prev))
        assert_page(2, prev, rows, next, stats, e5pp_15t_after2)

        del self.db['id-5']
        del self.db['id-4']
        del self.db['id-3']
        del self.db['id-2']
        prev, rows, next, stats = t(p.get(5, prev))
        assert_page(1, prev, rows, next, stats, e5pp_15t_after_secondpass)
Пример #16
0
 def test_jumpref(self):
     self.db['_design/test'] = {'views': {'test': {'map': 'function(doc) {emit(doc.letter+doc.letter, null);}'}}}
     self.db.update([{'letter': letter} for letter in 'abcdefghijklmnopqrstuvwxyz'])
     pager = Pager(self.db.view, 'test/test')
     p = pager.get(5)
     assert p['items'][0].key == 'aa'
     p = pager.get(5, Pager.jumpref('k'))
     assert p['items'][0].key == 'kk'
     p = pager.get(5, p['prev'])
     assert p['items'][0].key == 'ff'
     p = pager.get(5, p['prev'])
     assert p['items'][0].key == 'aa'
     assert p['prev'] is None
Пример #17
0
 def test_jumpref_exact(self):
     # Tests that the jump key is skipped if it is in the view
     self.db['_design/test'] = {'views': {'test': {'map': 'function(doc) {emit(doc.letter, null);}'}}}
     self.db.update([{'letter': letter} for letter in 'abcdefghijklmnopqrstuvwxyz'])
     pager = Pager(self.db.view, 'test/test')
     prev, items, next, stats = t(pager.get(5))
     assert items[0].key == 'a'
     prev, items, next, stats = t(pager.get(5, Pager.jumpref('k')))
     assert items[0].key == 'k'
     prev, items, next, stats = t(pager.get(5, prev))
     assert items[0].key == 'f'
     prev, items, next, stats = t(pager.get(5, prev))
     assert items[0].key == 'a'
     assert prev is None
Пример #18
0
 def test_remove_prevref(self):
     e5pp_15t_before = [ [2,3,4,5,6], [7,8,9,10,11], [12] ]
     e5pp_15t_after = [ [2,3,4,5], [7,8,9,10,11], [12] ]
     p = Pager(self.db.view, '%s/all'%model_type, dict(startkey=2, endkey=12))
     prev, rows, next, stats = t(p.get(5, None))
     assert_page(1, prev, rows, next, stats, e5pp_15t_before)
     del self.db['id-6']
     prev, rows, next, stats = t(p.get(5, next))
     assert_page(2, prev, rows, next, stats, e5pp_15t_after)
     prev, rows, next, stats = t(p.get(5, prev))
     assert_page(1, prev, rows, next, stats, e5pp_15t_after)
     prev, rows, next, stats = t(p.get(5, next))
     assert_page(2, prev, rows, next, stats, e5pp_15t_after)
     prev, rows, next, stats = t(p.get(5, next))
     assert_page(3, prev, rows, next, stats, e5pp_15t_after)
Пример #19
0
 def test_remove_prevref_reversed(self):
     e5pp_15t_before = [ [12,11,10,9,8],[7,6,5,4,3],[2]]
     e5pp_15t_after = [ [12,11,10,9],[7,6,5,4,3],[2]]
     p = Pager(self.db.view, '%s/all'%model_type, dict(startkey=12, endkey=2, descending=True))
     prev, rows, next, stats = t(p.get(5, None))
     assert_page(1, prev, rows, next, stats, e5pp_15t_before)
     del self.db['id-8']
     prev, rows, next, stats = t(p.get(5, next))
     assert_page(2, prev, rows, next, stats, e5pp_15t_after)
     prev, rows, next, stats = t(p.get(5, prev))
     assert_page(1, prev, rows, next, stats, e5pp_15t_after)
     prev, rows, next, stats = t(p.get(5, next))
     assert_page(2, prev, rows, next, stats, e5pp_15t_after)
     prev, rows, next, stats = t(p.get(5, next))
     assert_page(3, prev, rows, next, stats, e5pp_15t_after)