mirror of
https://github.com/valitydev/redash.git
synced 2024-11-07 09:28:51 +00:00
5096e4ed79
- Paginate the queries API result. - Split the API to /api/queries (all queries) and /api/queries/my which returns a user's queries (or drafts). - In the interface have explicit URLs for all queries (/queries), my queries (/queries/my) and drafts (/queries/drafts).
31 lines
1.1 KiB
Python
31 lines
1.1 KiB
Python
from werkzeug.exceptions import BadRequest
|
|
|
|
from redash.handlers.base import paginate
|
|
from unittest import TestCase
|
|
from mock import MagicMock
|
|
|
|
dummy_results = [i for i in range(25)]
|
|
|
|
|
|
class TestPaginate(TestCase):
|
|
def setUp(self):
|
|
self.query_set = MagicMock()
|
|
self.query_set.count = MagicMock(return_value=102)
|
|
self.query_set.paginate = MagicMock(return_value=dummy_results)
|
|
|
|
def test_returns_paginated_results(self):
|
|
page = paginate(self.query_set, 1, 25, lambda x: x)
|
|
self.assertEqual(page['page'], 1)
|
|
self.assertEqual(page['page_size'], 25)
|
|
self.assertEqual(page['count'], 102)
|
|
self.assertEqual(page['results'], dummy_results)
|
|
|
|
def test_raises_error_for_bad_page(self):
|
|
self.assertRaises(BadRequest, lambda: paginate(self.query_set, -1, 25, lambda x: x))
|
|
self.assertRaises(BadRequest, lambda: paginate(self.query_set, 6, 25, lambda x: x))
|
|
|
|
def test_raises_error_for_bad_page_size(self):
|
|
self.assertRaises(BadRequest, lambda: paginate(self.query_set, 1, 251, lambda x: x))
|
|
self.assertRaises(BadRequest, lambda: paginate(self.query_set, 1, -1, lambda x: x))
|
|
|