@@ -39,3 +39,31 @@ async def test_bad_json(self, httpx_mock, monkeypatch):
3939
4040 response = await fulltext .fulltext_search_api ({"q" : "hello" })
4141 assert response == {"error" : "Error converting search engine data to JSON" }
42+
43+ @pytest .mark .asyncio
44+ @pytest .mark .parametrize (
45+ ("page" , "limit" , "offset_kwarg" , "expected_from" ),
46+ [
47+ (1 , 20 , "NOT_PASSED" , 0 ), # offset not passed at all
48+ (1 , 20 , None , 0 ), # offset=None explicitly
49+ (10 , 20 , "NOT_PASSED" , 180 ), # offset not passed, page 10
50+ (5 , 20 , 100 , 100 ), # explicit offset provided
51+ ],
52+ )
53+ async def test_pagination_offset_calculation (
54+ self , httpx_mock , monkeypatch , page , limit , offset_kwarg , expected_from
55+ ):
56+ url = "http://mock"
57+ monkeypatch .setattr (
58+ config , "plugin_inside" , {"search_endpoint" : url }, raising = False
59+ )
60+ httpx_mock .add_response (json = {"hits" : {"hits" : []}})
61+
62+ # Conditionally build kwargs to test "not passed" scenario
63+ kwargs = {"page" : page , "limit" : limit }
64+ if offset_kwarg != "NOT_PASSED" :
65+ kwargs ["offset" ] = offset_kwarg
66+
67+ await fulltext .fulltext_search_async ("test" , ** kwargs )
68+ request = httpx_mock .get_request ()
69+ assert f"from={ expected_from } " in request .url .query .decode ()
0 commit comments