def test_iter_call_1(mocker, cli: BaseClient): with open("tests/test_data/instance_list.json") as fh: ret = load(fh) mocker.patch("lumapps.api.client.BaseClient._call", return_value=ret) lst = [i for i in cli.iter_call("instance/list")] assert len(lst) == 2
def test_iter_call_5(mocker, cli: BaseClient): with open("tests/test_data/instance_list_more_1.json") as fh: ret1 = load(fh) with open("tests/test_data/instance_list_more_2.json") as fh: ret2 = load(fh) def _call(name_parts: Sequence[str], params: dict, json=None): if "cursor" in params: return ret2 else: return ret1 mocker.patch("lumapps.api.client.BaseClient._call", side_effect=_call) iterator = cli.iter_call("instance/list") # 1st page, cursor is set lst = next(iterator) assert isinstance(lst, dict) assert cli.cursor == "foo_cursor" lst = next(iterator) assert isinstance(lst, dict) assert cli.cursor == "foo_cursor" # 2nd page, cursor is none lst = next(iterator) assert isinstance(lst, dict) assert cli.cursor is None lst = next(iterator) assert isinstance(lst, dict) assert cli.cursor is None # Assert iterator ended with raises(StopIteration): next(iterator) lst = [i for i in cli.iter_call("instance/list")] assert len(lst) == 4 assert cli.cursor is None
def test_iter_call_2(mocker, cli: BaseClient): with open("tests/test_data/instance_list_more_1.json") as fh: ret1 = load(fh) with open("tests/test_data/instance_list_more_2.json") as fh: ret2 = load(fh) def _call(name_parts: Sequence[str], params: dict, json=None): if "cursor" in params: return ret2 else: return ret1 mocker.patch("lumapps.api.client.BaseClient._call", side_effect=_call) lst = [i for i in cli.iter_call("instance/list")] assert len(lst) == 4