Test _applyQueryOpts.
This commit is contained in:
parent
8a54526d7d
commit
738f3553b5
1 changed files with 87 additions and 0 deletions
87
tests/test_hub/test_apply_query_opts.py
Normal file
87
tests/test_hub/test_apply_query_opts.py
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
import copy
|
||||
import unittest
|
||||
|
||||
from nose.tools import eq_
|
||||
|
||||
import kojihub
|
||||
|
||||
|
||||
class TestApplyQueryOpts(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.original = [
|
||||
{'foo': 1, 'bar': 1},
|
||||
{'foo': 2, 'bar': -1},
|
||||
{'foo': 0, 'bar': 0},
|
||||
]
|
||||
def test_basic(self):
|
||||
opts = None
|
||||
expected = copy.copy(self.original)
|
||||
actual = kojihub._applyQueryOpts(self.original, opts)
|
||||
eq_(expected, actual)
|
||||
|
||||
def test_order_by_foo(self):
|
||||
opts = {'order': 'foo'}
|
||||
expected = [
|
||||
{'foo': 0, 'bar': 0},
|
||||
{'foo': 1, 'bar': 1},
|
||||
{'foo': 2, 'bar': -1},
|
||||
]
|
||||
actual = kojihub._applyQueryOpts(self.original, opts)
|
||||
eq_(expected, actual)
|
||||
|
||||
def test_order_by_bar(self):
|
||||
opts = {'order': 'bar'}
|
||||
expected = [
|
||||
{'foo': 2, 'bar': -1},
|
||||
{'foo': 0, 'bar': 0},
|
||||
{'foo': 1, 'bar': 1},
|
||||
]
|
||||
actual = kojihub._applyQueryOpts(self.original, opts)
|
||||
eq_(expected, actual)
|
||||
|
||||
def test_order_in_reverse(self):
|
||||
opts = {'order': '-foo'}
|
||||
expected = [
|
||||
{'foo': 2, 'bar': -1},
|
||||
{'foo': 1, 'bar': 1},
|
||||
{'foo': 0, 'bar': 0},
|
||||
]
|
||||
actual = kojihub._applyQueryOpts(self.original, opts)
|
||||
eq_(expected, actual)
|
||||
|
||||
def test_offset(self):
|
||||
opts = {'offset': 1}
|
||||
expected = [
|
||||
{'foo': 2, 'bar': -1},
|
||||
{'foo': 0, 'bar': 0},
|
||||
]
|
||||
actual = kojihub._applyQueryOpts(self.original, opts)
|
||||
eq_(expected, actual)
|
||||
|
||||
def test_limit(self):
|
||||
opts = {'limit': 2}
|
||||
expected = [
|
||||
{'foo': 1, 'bar': 1},
|
||||
{'foo': 2, 'bar': -1},
|
||||
]
|
||||
actual = kojihub._applyQueryOpts(self.original, opts)
|
||||
eq_(expected, actual)
|
||||
|
||||
def test_limit_and_offset(self):
|
||||
opts = {'limit': 1, 'offset': 1}
|
||||
expected = [
|
||||
{'foo': 2, 'bar': -1},
|
||||
]
|
||||
actual = kojihub._applyQueryOpts(self.original, opts)
|
||||
eq_(expected, actual)
|
||||
|
||||
def test_count_only(self):
|
||||
opts = {'countOnly': True}
|
||||
expected = 3
|
||||
actual = kojihub._applyQueryOpts(self.original, opts)
|
||||
eq_(expected, actual)
|
||||
|
||||
opts = {'countOnly': True, 'offset': 2}
|
||||
expected = 1
|
||||
actual = kojihub._applyQueryOpts(self.original, opts)
|
||||
eq_(expected, actual)
|
||||
Loading…
Add table
Add a link
Reference in a new issue