diff --git a/otcextensions/sdk/dns/v2/_base.py b/otcextensions/sdk/dns/v2/_base.py index 40601a5f7..10f0c7e60 100644 --- a/otcextensions/sdk/dns/v2/_base.py +++ b/otcextensions/sdk/dns/v2/_base.py @@ -77,7 +77,6 @@ def _get_next_link(cls, uri, response, data, marker, limit, total_yielded): links = data.get('links') if links: next_link = links.get('next') - total = data.get('metadata', {}).get('total_count') if total: # We have a kill switch @@ -98,8 +97,9 @@ def _get_next_link(cls, uri, response, data, marker, limit, total_yielded): # If we still have no link, and limit was given and is non-zero, # and the number of records yielded equals the limit, then the user # is playing pagination ball so we should go ahead and try once more. - if not next_link and limit: + if not next_link: next_link = uri params['marker'] = marker - params['limit'] = limit + if limit: + params['limit'] = limit return next_link, params diff --git a/otcextensions/tests/unit/sdk/dns/v2/test_recordset.py b/otcextensions/tests/unit/sdk/dns/v2/test_recordset.py index 857bb663f..2168d962a 100644 --- a/otcextensions/tests/unit/sdk/dns/v2/test_recordset.py +++ b/otcextensions/tests/unit/sdk/dns/v2/test_recordset.py @@ -36,6 +36,29 @@ } +DATA = { + "links": { + "self": "https://example.com/v2/zones/2/recordsets" + }, + "recordsets": [ + { + "id": "1", + "name": "prod.otc.1." + }, + { + "id": "a3", + "name": "prod.otc.2." + }, + { + "id": "a7", + "name": "prod.otc.3." + } + ], + "metadata": { + "total_count": 7 + } +} + class TestRecordSet(base.TestCase): @@ -61,3 +84,49 @@ def test_make_it(self): self.assertEqual(EXAMPLE['zone_id'], sot.zone_id) self.assertEqual(EXAMPLE['create_at'], sot.created_at) self.assertEqual(EXAMPLE['update_at'], sot.updated_at) + + def test_get_next_link(self): + uri = '/zones/2/recordsets' + marker = 'a7' + + result = recordset.Recordset._get_next_link( + uri=uri, + response=None, + data=DATA, + marker=marker, + limit=None, + total_yielded=3 + ) + self.assertEqual(uri, result[0]) + self.assertEqual({'marker': marker}, result[1]) + + def test_get_next_link2(self): + uri = '/zones/2/recordsets' + marker = 'a7' + + result = recordset.Recordset._get_next_link( + uri=uri, + response=None, + data=DATA, + marker=marker, + limit=None, + total_yielded=7 + ) + self.assertEqual(None, result[0]) + self.assertEqual({}, result[1]) + + def test_get_next_link3(self): + uri = '/zones/2/recordsets' + marker = 'a7' + limit = 3 + + result = recordset.Recordset._get_next_link( + uri=uri, + response=None, + data=DATA, + marker=marker, + limit=3, + total_yielded=3 + ) + self.assertEqual(uri, result[0]) + self.assertEqual({'marker': marker, 'limit': limit}, result[1])