|
11 | 11 | from sasctl.core import PageIterator, RestObj
|
12 | 12 |
|
13 | 13 |
|
| 14 | +def test_no_paging_required(): |
| 15 | + """If "next" link not present, current items should be included.""" |
| 16 | + |
| 17 | + items = [{"name": "a"}, {"name": "b"}, {"name": "c"}] |
| 18 | + obj = RestObj(items=items, count=len(items)) |
| 19 | + |
| 20 | + with mock.patch("sasctl.core.request") as request: |
| 21 | + pager = PageIterator(obj) |
| 22 | + |
| 23 | + # Returned page of items should preserve item order |
| 24 | + items = next(pager) |
| 25 | + for idx, item in enumerate(items): |
| 26 | + assert item.name == RestObj(items[idx]).name |
| 27 | + |
| 28 | + # No request should have been made to retrieve additional data. |
| 29 | + try: |
| 30 | + request.assert_not_called() |
| 31 | + except AssertionError as e: |
| 32 | + raise AssertionError( |
| 33 | + f"method_calls={request.mock_calls} call_args={request.call_args_list}" |
| 34 | + ) |
| 35 | + |
| 36 | + |
14 | 37 | @pytest.fixture(params=[(6, 2, 2), (6, 1, 4), (6, 5, 4), (6, 6, 2), (100, 10, 20)])
|
15 | 38 | def paging(request):
|
16 | 39 | """Create a RestObj designed to page through a collection of items and the
|
@@ -53,29 +76,6 @@ def side_effect(_, link, **kwargs):
|
53 | 76 | assert req.call_count >= math.ceil(call_count)
|
54 | 77 |
|
55 | 78 |
|
56 |
| -def test_no_paging_required(): |
57 |
| - """If "next" link not present, current items should be included.""" |
58 |
| - |
59 |
| - items = [{"name": "a"}, {"name": "b"}, {"name": "c"}] |
60 |
| - obj = RestObj(items=items, count=len(items)) |
61 |
| - |
62 |
| - with mock.patch("sasctl.core.request") as request: |
63 |
| - pager = PageIterator(obj) |
64 |
| - |
65 |
| - # Returned page of items should preserve item order |
66 |
| - items = next(pager) |
67 |
| - for idx, item in enumerate(items): |
68 |
| - assert item.name == RestObj(items[idx]).name |
69 |
| - |
70 |
| - # No request should have been made to retrieve additional data. |
71 |
| - try: |
72 |
| - request.assert_not_called() |
73 |
| - except AssertionError as e: |
74 |
| - raise AssertionError( |
75 |
| - f"method_calls={request.mock_calls} call_args={request.call_args_list}" |
76 |
| - ) |
77 |
| - |
78 |
| - |
79 | 79 | def test_paging_required(paging):
|
80 | 80 | """Requests should be made to retrieve additional pages."""
|
81 | 81 | obj, items, _ = paging
|
|
0 commit comments