From 368b1ed24c29065b8e0d564004adef812b82a01b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dawid=20P=C5=82ocki?= Date: Mon, 19 Feb 2024 20:46:02 +0100 Subject: [PATCH] Add and implement the test test_should_return_last_according_the_feed_order_with_gap_between_files --- podcast_downloader/downloaded.py | 3 +++ ...et_last_downloaded_file_before_gap_test.py | 26 ++++++++++++++++--- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/podcast_downloader/downloaded.py b/podcast_downloader/downloaded.py index 83c94b5..b90c282 100644 --- a/podcast_downloader/downloaded.py +++ b/podcast_downloader/downloaded.py @@ -42,5 +42,8 @@ def get_last_downloaded_file_before_gap( for feed_file_name in feed_files: if feed_file_name in all_downloaded_files: last_file = feed_file_name + else: + if last_file != None: + return last_file return last_file diff --git a/tests/get_last_downloaded_file_before_gap_test.py b/tests/get_last_downloaded_file_before_gap_test.py index 682024a..7867593 100644 --- a/tests/get_last_downloaded_file_before_gap_test.py +++ b/tests/get_last_downloaded_file_before_gap_test.py @@ -34,7 +34,7 @@ def test_should_return_last_for_nonempty_directory_files(self): # Assert self.assertEqual( - result, feed_files[-1], "Should return the last files from the feed" + result, feed_files[-1], "Should return the last file from the feed" ) def test_should_return_last_according_the_feed_order(self): @@ -50,7 +50,7 @@ def test_should_return_last_according_the_feed_order(self): # Assert self.assertEqual( - result, feed_files[-1], "Should return the last files from the feed" + result, feed_files[-1], "Should return the last file from the feed" ) def test_should_return_last_according_the_feed_order_when_feed_is_longer(self): @@ -66,7 +66,27 @@ def test_should_return_last_according_the_feed_order_when_feed_is_longer(self): # Assert self.assertEqual( - result, feed_files[-3], "Should return the last files from the feed" + result, + feed_files[-3], + "Should return the last file (according to feed) which is downloaded", + ) + + def test_should_return_last_according_the_feed_order_with_gap_between_files(self): + # Assign + feed_files = list(generate_podcast_files_episodes(8)) + + directory_files = feed_files[2:4] + [feed_files[-2]] + shuffle(directory_files) + directory_files.insert(0, feed_files[-4]) + + # Act + result = get_last_downloaded_file_before_gap(feed_files, directory_files) + + # Assert + self.assertEqual( + result, + feed_files[-4], + "Should return the last file (according to feed) before gap which is downloaded", )