@@ -227,12 +227,46 @@ def test_make_links_with_configured_url(self, request_mock):
227
227
helper = pagination .PaginationHelper (params )
228
228
links = helper ._make_links (model_list )
229
229
self .assertEqual (links [0 ].rel , "previous" )
230
+ self .assertEqual (
231
+ links [0 ].href ,
232
+ ("{base_uri}{path}?limit={limit}&marker={marker}"
233
+ "&page_reverse=True" ).format (
234
+ base_uri = api_base_uri ,
235
+ path = request_mock .path ,
236
+ limit = params ['limit' ],
237
+ marker = member1 .id
238
+ ))
239
+ self .assertEqual (links [1 ].rel , "next" )
230
240
self .assertEqual (
231
241
links [1 ].href ,
232
242
"{base_uri}{path}?limit={limit}&marker={marker}" .format (
233
243
base_uri = api_base_uri ,
234
244
path = request_mock .path ,
235
245
limit = params ['limit' ],
246
+ marker = member1 .id ))
247
+
248
+ @mock .patch ('octavia.api.common.pagination.request' )
249
+ def test_make_links_with_zero_limit (self , request_mock ):
250
+ request_mock .path = "/lbaas/v2/pools/1/members"
251
+ request_mock .path_url = "http://localhost" + request_mock .path
252
+ api_base_uri = "https://127.0.0.1"
253
+ conf = self .useFixture (oslo_fixture .Config (cfg .CONF ))
254
+ conf .config (group = 'api_settings' , api_base_uri = api_base_uri )
255
+ member1 = models .Member ()
256
+ member1 .id = uuidutils .generate_uuid ()
257
+ model_list = [member1 ]
258
+
259
+ params = {'limit' : 0 , 'marker' : member1 .id }
260
+ helper = pagination .PaginationHelper (params )
261
+ links = helper ._make_links (model_list )
262
+ self .assertEqual (links [0 ].rel , "previous" )
263
+ self .assertEqual (
264
+ links [0 ].href ,
265
+ ("{base_uri}{path}?limit={limit}&marker={marker}"
266
+ "&page_reverse=True" ).format (
267
+ base_uri = api_base_uri ,
268
+ path = request_mock .path ,
269
+ limit = None ,
236
270
marker = member1 .id
237
271
))
238
272
self .assertEqual (links [1 ].rel , "next" )
@@ -241,5 +275,38 @@ def test_make_links_with_configured_url(self, request_mock):
241
275
"{base_uri}{path}?limit={limit}&marker={marker}" .format (
242
276
base_uri = api_base_uri ,
243
277
path = request_mock .path ,
244
- limit = params ['limit' ],
278
+ limit = None ,
279
+ marker = member1 .id ))
280
+
281
+ @mock .patch ('octavia.api.common.pagination.request' )
282
+ def test_make_links_with_negative_limit (self , request_mock ):
283
+ request_mock .path = "/lbaas/v2/pools/1/members"
284
+ request_mock .path_url = "http://localhost" + request_mock .path
285
+ api_base_uri = "https://127.0.0.1"
286
+ conf = self .useFixture (oslo_fixture .Config (cfg .CONF ))
287
+ conf .config (group = 'api_settings' , api_base_uri = api_base_uri )
288
+ member1 = models .Member ()
289
+ member1 .id = uuidutils .generate_uuid ()
290
+ model_list = [member1 ]
291
+
292
+ params = {'limit' : - 1 , 'marker' : member1 .id }
293
+ helper = pagination .PaginationHelper (params )
294
+ links = helper ._make_links (model_list )
295
+ self .assertEqual (links [0 ].rel , "previous" )
296
+ self .assertEqual (
297
+ links [0 ].href ,
298
+ ("{base_uri}{path}?limit={limit}&marker={marker}"
299
+ "&page_reverse=True" ).format (
300
+ base_uri = api_base_uri ,
301
+ path = request_mock .path ,
302
+ limit = None ,
303
+ marker = member1 .id
304
+ ))
305
+ self .assertEqual (links [1 ].rel , "next" )
306
+ self .assertEqual (
307
+ links [1 ].href ,
308
+ "{base_uri}{path}?limit={limit}&marker={marker}" .format (
309
+ base_uri = api_base_uri ,
310
+ path = request_mock .path ,
311
+ limit = None ,
245
312
marker = member1 .id ))
0 commit comments