Techdebt: Paginator should support OrderedDict's (#6723)
This commit is contained in:
parent
b6a582e624
commit
6eb16e8038
@ -149,7 +149,7 @@ class Paginator:
|
|||||||
token_dict["parameterChecksum"] = self._param_checksum
|
token_dict["parameterChecksum"] = self._param_checksum
|
||||||
range_keys = []
|
range_keys = []
|
||||||
for attr in self._unique_attributes:
|
for attr in self._unique_attributes:
|
||||||
if type(next_item) == dict:
|
if isinstance(next_item, dict):
|
||||||
range_keys.append(str(next_item[attr]))
|
range_keys.append(str(next_item[attr]))
|
||||||
else:
|
else:
|
||||||
range_keys.append(str(getattr(next_item, attr)))
|
range_keys.append(str(getattr(next_item, attr)))
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
from collections import OrderedDict
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
@ -38,6 +39,12 @@ def test_paginator__paginate_with_just_max_results():
|
|||||||
assert page == results
|
assert page == results
|
||||||
|
|
||||||
|
|
||||||
|
def test_paginator__ordered_dict():
|
||||||
|
p = Paginator(max_results=1, unique_attribute="id")
|
||||||
|
page, _ = p.paginate([OrderedDict(x) for x in results])
|
||||||
|
assert len(page) == 1
|
||||||
|
|
||||||
|
|
||||||
def test_paginator__paginate_without_range_key__throws_error():
|
def test_paginator__paginate_without_range_key__throws_error():
|
||||||
p = Paginator(max_results=2)
|
p = Paginator(max_results=2)
|
||||||
with pytest.raises(KeyError):
|
with pytest.raises(KeyError):
|
||||||
|
Loading…
Reference in New Issue
Block a user