How to use _jsonify_items method in Lemoncheesecake

Best Python code snippet using lemoncheesecake

test_pagination.py

Source:test_pagination.py Github

copy

Full Screen

...4class PaginatorTestCase(UnitTestBase):5 def test_jsonify_items_when_no_items(self):6 items, total = SampleModel.query.all(), SampleModel.query.count()7 p = Pagination(SampleModel.query, 1, 0, total, items)8 self.assertEqual(p._jsonify_items(), [])9 def test_jsonify_items_when_some_exist(self):10 SampleModel.manager.create(**{})11 items, total = SampleModel.query.all(), SampleModel.query.count()12 p = Pagination(SampleModel.query, 1, 1, total, items)13 self.assertNotEqual(p._jsonify_items(), [])14 def test_assert_pages_is_zero_when_per_page_is_zero(self):15 items, total = SampleModel.query.all(), SampleModel.query.count()16 p = Pagination(SampleModel.query, 1, 0, total, items)17 self.assertEqual(p.pages, 0)18 def test_iter_pages(self):19 SampleModel.manager.create(**{})20 items, total = SampleModel.query.all(), SampleModel.query.count()21 p = Pagination(SampleModel.query, 1, 1, total, items)22 self.assertNotEqual(p._jsonify_items(), [])23 _ = [i for i in p.iter_pages()]24 self.assertIn(1, _)25class PaginationTestCase(UnitTestBase):26 def test_paginate_no_records_in_db(self):27 paginator = SampleModel.manager.paginate()28 self.assertEqual(paginator.has_next, False)29 self.assertEqual(paginator.has_prev, False)30 self.assertEqual(paginator.page, 1)31 self.assertEqual(paginator.prev_num, 0)32 self.assertEqual(paginator.next_num, 2)33 self.assertEqual(paginator.pages, 0)34 self.assertEqual(paginator.total, 0)35 def test_paginator_two_records_in_db_default_settings(self):36 model1 = SampleModel()...

Full Screen

Full Screen

paginator.py

Source:paginator.py Github

copy

Full Screen

...10 self.per_page = per_page11 self.total = total12 self.items = items13 self.extra = kwargs14 def _jsonify_items(self):15 if not self.items:16 return []17 return self.items18 @property19 def pages(self):20 if self.per_page == 0:21 pages = 022 else:23 pages = int(ceil(self.total / float(self.per_page)))24 return pages25 @property26 def prev_num(self):27 return self.page - 128 @property29 def has_prev(self):30 return self.page > 131 @property32 def has_next(self):33 return self.page < self.pages34 @property35 def next_num(self):36 return self.page + 137 def iter_pages(self, left_edge=2, left_current=2,38 right_current=5, right_edge=2):39 last = 040 for num in xrange(1, self.pages + 1):41 if num <= left_edge or \42 (num > self.page - left_current - 1 and43 num < self.page + right_current) or \44 num > self.pages - right_edge:45 if last + 1 != num:46 yield None47 yield num48 last = num49 def __json__(self, request=None):50 return {51 'meta': {52 'previous': self.prev_num if self.has_prev else None,53 'next': self.next_num if self.has_next else None,54 'per_page': self.per_page,55 'total_entries': self.total,56 'page': self.page,57 'total_pages': self.pages58 },59 'items': self._jsonify_items(),60 'extra': self.extra61 }62def paginate(qs, page=1, per_page=20, **kwargs):63 if page < 1:64 raise PaginationException(u"Page has to be grater or equal 1")65 if per_page < 0:66 raise PaginationException(u"Page has to be grater than 0")67 total = int(qs.count())68 if total < (page-1) * per_page:69 page, per_page = 1, 2070 items = qs.limit(per_page).offset((page - 1) * per_page).all()71 if not items and page != 1:72 return False73 return Pagination(qs, page, per_page, total, items, **kwargs)

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Lemoncheesecake automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful