def test_dict(self): result = {'foo': 'bar'} func = Mock() final_result = Mock() with patch.multiple( pbm, invoke_with_throttling_retries=DEFAULT, _paginate_resultset=DEFAULT, _paginate_dict=DEFAULT, logger=DEFAULT, ) as mocks: mocks['invoke_with_throttling_retries'].return_value = result mocks['_paginate_dict'].return_value = final_result res = paginate_query( func, 'foo', bar='barval', alc_marker_path=[], alc_data_path=[], alc_marker_param='p' ) assert res == final_result assert mocks['invoke_with_throttling_retries'].mock_calls == [ call(func, 'foo', bar='barval', alc_marker_path=[], alc_data_path=[], alc_marker_param='p') ] assert mocks['_paginate_resultset'].mock_calls == [] assert mocks['_paginate_dict'].mock_calls == [ call(result, func, 'foo', bar='barval', alc_marker_path=[], alc_data_path=[], alc_marker_param='p') ] assert mocks['logger'].mock_calls == []
def test_dict_missing_params(self): result = {'foo': 'bar'} func = Mock() final_result = Mock() with patch.multiple( pbm, invoke_with_throttling_retries=DEFAULT, _paginate_resultset=DEFAULT, _paginate_dict=DEFAULT, logger=DEFAULT, ) as mocks: mocks['invoke_with_throttling_retries'].return_value = result mocks['_paginate_dict'].return_value = final_result res = paginate_query( func, 'foo', bar='barval' ) assert res == result assert mocks['invoke_with_throttling_retries'].mock_calls == [ call(func, 'foo', bar='barval') ] assert mocks['_paginate_resultset'].mock_calls == [] assert mocks['_paginate_dict'].mock_calls == [] assert len(mocks['logger'].mock_calls) == 1 args = mocks['logger'].warning.mock_calls[0][1] assert len(args) == 1 assert args[0].startswith( "Query returned a dict, but does not have _paginate_dict params " "set; cannot paginate (<Mock id='") is True
def test_resultset_no_next(self): result = ResultSet() func = Mock() with patch.multiple( pbm, invoke_with_throttling_retries=DEFAULT, _paginate_resultset=DEFAULT, _paginate_dict=DEFAULT, ) as mocks: mocks['invoke_with_throttling_retries'].return_value = result res = paginate_query(func, 'foo', bar='barval') assert res == result assert mocks['invoke_with_throttling_retries'].mock_calls == [ call(func, 'foo', bar='barval') ] assert mocks['_paginate_resultset'].mock_calls == [] assert mocks['_paginate_dict'].mock_calls == []
def test_result_AccountLimits(self): func = Mock() result = AccountLimits() with patch.multiple( pbm, invoke_with_throttling_retries=DEFAULT, _paginate_resultset=DEFAULT, _paginate_dict=DEFAULT, logger=DEFAULT, ) as mocks: mocks['invoke_with_throttling_retries'].return_value = result res = paginate_query(func, 'foo', bar='barval') assert res == result assert mocks['invoke_with_throttling_retries'].mock_calls == [ call(func, 'foo', bar='barval') ] assert mocks['_paginate_resultset'].mock_calls == [] assert mocks['_paginate_dict'].mock_calls == [] assert mocks['logger'].mock_calls == []
def test_other_type(self): func = Mock() with patch.multiple( pbm, invoke_with_throttling_retries=DEFAULT, _paginate_resultset=DEFAULT, _paginate_dict=DEFAULT, logger=DEFAULT, ) as mocks: mocks['invoke_with_throttling_retries'].return_value = 'foobar' res = paginate_query(func, 'foo', bar='barval') assert res == 'foobar' assert mocks['invoke_with_throttling_retries'].mock_calls == [ call(func, 'foo', bar='barval') ] assert mocks['_paginate_resultset'].mock_calls == [] assert mocks['_paginate_dict'].mock_calls == [] assert mocks['logger'].mock_calls == [ call.warning("Query result of type %s cannot be paginated", type('foo')) ]