def test_defaults(self):
        """Size and offset set to zero by default."""
        def verify(pagination):
            self.assertDictEqual(pagination, {})
            return Mock()

        with patch('manager_rest.rest.rest_decorators.request') as request:
            request.args = {}
            paginate(verify)()
Пример #2
0
    def test_defaults(self):
        """Size and offset set to zero by default."""
        def verify(pagination):
            self.assertDictEqual(pagination, {})
            return Mock()

        with patch('manager_rest.rest.rest_decorators.request') as request:
            request.args = {}
            paginate(verify)()
    def test_negative(self):
        """Exception raised when negative value is passed."""
        def verify(pagination):
            return Mock()

        with patch('manager_rest.rest.rest_decorators.request') as request:
            for args in [{'_size': '-1', '_offset': '-1'}]:
                request.args = args
                with self.assertRaises(Invalid):
                    paginate(verify)()
Пример #4
0
    def test_negative(self):
        """Exception raised when negative value is passed."""
        def verify(pagination):
            return Mock()

        with patch('manager_rest.rest.rest_decorators.request') as request:
            for args in [{'_size': '-1', '_offset': '-1'}]:
                request.args = args
                with self.assertRaises(Invalid):
                    paginate(verify)()
    def test_coercion(self):
        """Values passed as strings are coerced to integers."""
        def verify(pagination):
            self.assertEqual(pagination['size'], 1)
            self.assertEqual(pagination['offset'], 2)
            return Mock()

        with patch('manager_rest.rest.rest_decorators.request') as request:
            request.args = {
                '_size': '1',
                '_offset': '2',
            }
            paginate(verify)()
Пример #6
0
    def test_coercion(self):
        """Values passed as strings are coerced to integers."""
        def verify(pagination):
            self.assertEqual(pagination['size'], 1)
            self.assertEqual(pagination['offset'], 2)
            return Mock()

        with patch('manager_rest.rest.rest_decorators.request') as request:
            request.args = {
                '_size': '1',
                '_offset': '2',
            }
            paginate(verify)()