I am having this method below:
def pagination_logic(self, topic_name):
"""Pagination logic to fetch the complete data.
:param topic_name:str, kafka topic name.
"""
while self.next_page_cursor:
self.fetch_response_from_api()
records = self.extract_records()
self.publish_records(records, topic_name)
if not self.flag:
break
self.extract_next_page_cursor()
self.page += 1
else:
logger.info("Finished fetching data")
I need to write a unit test method. Below is my unit test method
def test_pagination_logic(self):
"""Test for pagination logic."""
allow(self.slack).fetch_response_from_api.and_return(None)
allow(self.slack).extract_records.and_return(RESPONSE.get('entries'))
allow(self.slack).publish_records.and_return(None)
allow(self.slack).extract_next_page_cursor.and_return(None)
self.slack.next_page_cursor = 'abc'
self.slack.flag = 0
result = self.slack.pagination_logic('topic_name')
assert result is None
I know that I can achieve 100% coverage for this by setting the value of self.flag as 1 for the first iteration and 0 for the second iteration.
But how can I achieve that?.