From f57b866647b356dab561647131dafea73b762b0d Mon Sep 17 00:00:00 2001 From: Ralph Bean Date: Jun 04 2016 21:27:26 +0000 Subject: Test _applyQueryOpts. --- diff --git a/tests/test_hub/test_apply_query_opts.py b/tests/test_hub/test_apply_query_opts.py new file mode 100644 index 0000000..653723c --- /dev/null +++ b/tests/test_hub/test_apply_query_opts.py @@ -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)