henry3260 commented on code in PR #70989:
URL: https://github.com/apache/airflow/pull/70989#discussion_r3714299471


##########
airflow-ctl/tests/airflow_ctl/api/test_operations.py:
##########
@@ -250,6 +250,23 @@ def 
test_execute_list_sends_limit_on_subsequent_pages(self):
         for call in mock_client.get.call_args_list:
             assert call.kwargs["params"]["limit"] == 2
 
+    def test_execute_list_sends_offset_to_server(self):
+        """``offset`` must reach the server on the first request, not only on 
subsequent pages."""
+        mock_client = Mock()
+        mock_client.get.side_effect = [
+            Mock(content=json.dumps({"hellos": [{"name": "c"}, {"name": "d"}], 
"total_entries": 6})),
+            Mock(content=json.dumps({"hellos": [{"name": "e"}, {"name": "f"}], 
"total_entries": 6})),
+        ]
+        base_operation = BaseOperations(client=mock_client)
+
+        response = base_operation.execute_list(
+            path="hello", data_model=HelloCollectionResponse, offset=2, limit=2
+        )
+
+        assert [call.kwargs["params"]["offset"] for call in 
mock_client.get.call_args_list] == [2, 4]
+        # The paging loop resumes at offset + limit, so a dropped offset also 
skips rows 2-3.

Review Comment:
   ```suggestion
           rows = [{"name": name} for name in "abcdef"]
   
           def paged(path, params):
               # An absent ``offset`` is what the server would see as its own 
default of 0.
               start = params.get("offset", 0)
               return Mock(
                   content=json.dumps(
                       {"hellos": rows[start : start + params["limit"]], 
"total_entries": len(rows)}
                   )
               )
   
           mock_client = Mock()
           mock_client.get.side_effect = paged
           base_operation = BaseOperations(client=mock_client)
   
           response = base_operation.execute_list(
               path="hello", data_model=HelloCollectionResponse, offset=2, 
limit=2
           )
   
           assert [hello.name for hello in response.hellos] == ["c", "d", "e", 
"f"]
   
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to