def test_page_with_negative_index(self, m_fetch): """Test providing page with a negative index and a size.""" q = Query('Environment') q.page(index=-10, pagesize=500) expected = "SKIP 0" self.assertTrue(expected in str(q)) expected = "LIMIT 500" self.assertTrue(expected in str(q))
def test_page_with_page(self, m_fetch): """Test providing page with a page and a size.""" q = Query('Environment') q.page(page=3, pagesize=500) expected = "SKIP 1000" self.assertTrue(expected in str(q)) expected = "LIMIT 500" self.assertTrue(expected in str(q))
def test_page_defaults(self, m_fetch): """Test default arguments to page() method.""" q = Query('Environment') q.page() expected = 'SKIP 0' self.assertTrue(expected in str(q)) expected = 'LIMIT 100' self.assertTrue(expected in str(q))
def search(self, request): """Search objects by type, identity, and property filters.""" search = SearchSerializer(data=request.data) if not search.is_valid(): raise ValidationError(search.errors) vd = search.validated_data query = Query(vd.get('model')) \ .identity(vd.get('identity')) \ .time(vd.get('time')) for f in vd.get('filters', []): query.filter(f['prop'], f['operator'], f['value'], label=f['model']) for o in vd.get('orders', []): query.orderby(o['prop'], o['direction'], label=o['model']) count = query.count() records = query.page(page=vd['page'], pagesize=vd['pagesize'], index=vd.get('index')) serializer = GenericSerializer({ 'query': str(query), 'data': vd, 'params': query.params, 'count': count, 'pagesize': vd['pagesize'], 'page': vd['page'], 'records': records }) return Response(serializer.data)