def test_next_verify_are_there_more_results_and_next_page_called( self, mock_are_there_more_results, mock_next_page, mock_session, mock_value_holder_to_ion_value): updated_result = '1' def update_page(): stream_cursor._page = { 'NextPageToken': None, 'Values': [updated_result] } stream_cursor._index = 0 mock_are_there_more_results.return_value = True mock_value_holder_to_ion_value.side_effect = lambda val: val mock_session.return_value = None mock_next_page.return_value = None mock_next_page.side_effect = update_page stream_cursor = StreamCursor(MOCK_STATEMENT_RESULT, mock_session, MOCK_TRANSACTION_ID) stream_cursor._index = len(MOCK_ION_BINARY_VALUES) self.assertEqual(next(stream_cursor), updated_result) mock_next_page.assert_called_once_with() mock_are_there_more_results.assert_called_once_with() mock_value_holder_to_ion_value.assert_called_once_with(updated_result)
def test_next_with_next_page_returns_empty_values_and_not_none_token(self, mock_session): mock_session.return_value = None stream_cursor = StreamCursor(MOCK_STATEMENT_RESULT, mock_session, MOCK_TRANSACTION_ID) stream_cursor._index = len(MOCK_ION_BINARY_VALUES) mock_session._fetch_page.side_effect = [{'Page': {'NextPageToken': 'token', 'Values': []}}, {'Page': {'NextPageToken': None, 'Values': []}}] self.assertRaises(StopIteration, next, stream_cursor)
def test_next_when_next_page_returns_empty_values_and_none_token(self, mock_session, mock_next_page): mock_session.return_value = None def next_page(): stream_cursor._page = {'NextPageToken': None, 'Values': []} stream_cursor._index = 0 stream_cursor = StreamCursor(MOCK_STATEMENT_RESULT, mock_session, MOCK_TRANSACTION_ID) stream_cursor._index = len(MOCK_ION_BINARY_VALUES) mock_next_page.side_effect = next_page self.assertRaises(StopIteration, next, stream_cursor)