@@ -33,7 +33,7 @@ def setUp(self):
3333 self .verify = False
3434 self .dnac = DnaCenterClient (self .url , self .username , self .password , verify = self .verify )
3535 self .dnac .conn = MagicMock ()
36- self .dnac .conn .sites .get_site_count .return_value = {"response" : 4 }
36+ self .dnac .conn .sites .get_site_count .return_value = {"response" : 31 }
3737 self .dnac .conn .devices .get_device_count .return_value = {"response" : 3 }
3838
3939 self .mock_response = create_autospec (Response )
@@ -70,6 +70,26 @@ def test_get_locations(self):
7070 actual = self .dnac .get_locations ()
7171 self .assertEqual (actual , LOCATION_FIXTURE )
7272
73+ def test_get_locations_pagination (self ):
74+ """Test the get_locations method correctly paginates without skipping items.
75+
76+ Simulates a 1-based offset API returning a fixed page size. With N total items
77+ and page_size P, an off-by-one in offset causes one duplicate per page. When the
78+ accumulated duplicates inflate loc_data to >= total before all unique items are
79+ fetched, the loop exits early and items are silently skipped.
80+ """
81+ all_locations = RECV_LOCATION_FIXTURE ["response" ][:30 ]
82+
83+ def fake_get_site (offset = 1 , limit = 10 , ** kwargs ):
84+ """Simulate 1-based offset API returning up to limit items."""
85+ start = offset - 1
86+ return {"response" : all_locations [start : start + limit ]}
87+
88+ self .dnac .conn .sites .get_site .side_effect = fake_get_site
89+ self .dnac .conn .sites .get_site_count .return_value = {"response" : len (all_locations )}
90+ actual = self .dnac .get_locations ()
91+ self .assertEqual (len (actual ), len (all_locations ))
92+
7393 def test_get_locations_catches_api_error (self ):
7494 """Test the get_locations method in DnaCenterClient catches dnacentersdkException."""
7595 self .dnac .conn .sites .get_site .side_effect = dnacentersdkException (self .mock_response )
0 commit comments