예제 #1
0
    def test_get_request_limit_param_with_limit_zero_allowed(self):
        """
        _get_request_limit_param can accept request it limit <= 0
        So here test that and returns a valid number
        """
        limits = [(0, 0), (-1, -1), (-1000, -1000)]

        for req_limit, resp_limit in limits:
            request = testing.DummyRequest(params={'limit': req_limit})
            result_limit = articlemeta._get_request_limit_param(
                request, only_positive_limit=False)
            self.assertEqual(result_limit, resp_limit)
예제 #2
0
    def test_get_request_limit_param__can_ignore_default_limit(self):
        """
        In some case every requested limit, must be the returned,
        even if is bigger than default_limit.
        """
        # set a list of tuples (limit requested, limit expected in response)
        limits = [(1, 1), (10, 10), (1000, 1000), (2000, 2000), (12000, 12000)]

        for req_limit, resp_limit in limits:
            request = testing.DummyRequest(params={'limit': req_limit})
            result_limit = articlemeta._get_request_limit_param(
                request, force_max_limit_to_default=False)
            self.assertEqual(result_limit, resp_limit)
예제 #3
0
    def test_get_request_limit_param_by_default(self):
        """
        test default behavior of the helper function: _get_request_limit_param
        - only positive limits are allowed
        - if request.limit is greater than default_limit, will return the default limit (1000)
        """
        # set a list of tuples (limit requested, limit expected in response)
        limits = [(1, 1), (10, 10), (1000, 1000), (2000, 1000), (12000, 1000)]

        for req_limit, resp_limit in limits:
            request = testing.DummyRequest(params={'limit': req_limit})
            result_limit = articlemeta._get_request_limit_param(request)
            self.assertEqual(result_limit, resp_limit)
예제 #4
0
    def test_get_request_limit_param_with_new_default_limit(self):
        """
        define new default limit, that will be the top value returned
        """
        new_default_limit = 200
        # set a list of tuples (limit requested, limit expected in response)
        limits = [(1, 1), (10, 10), (1000, new_default_limit),
                  (2000, new_default_limit), (12000, new_default_limit)]

        for req_limit, resp_limit in limits:
            request = testing.DummyRequest(params={'limit': req_limit})
            result_limit = articlemeta._get_request_limit_param(
                request, default_limit=new_default_limit)
            self.assertEqual(result_limit, resp_limit)