Skip to content

Commit

Permalink
Add test_should_return_last_according_the_feed_order
Browse files Browse the repository at this point in the history
  • Loading branch information
dplocki committed Feb 18, 2024
1 parent d3b9298 commit b3bfc21
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
9 changes: 8 additions & 1 deletion podcast_downloader/downloaded.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,11 @@ def get_downloaded_files(
def get_last_downloaded_file_before_gap(
feed_files: List[str], downloaded_files: Iterable[str]
) -> str:
return downloaded_files[-1] if downloaded_files else None
last_file = None
all_downloaded_files = set(downloaded_files)

for feed_file_name in feed_files:
if feed_file_name in all_downloaded_files:
last_file = feed_file_name

return last_file
30 changes: 27 additions & 3 deletions tests/get_last_downloaded_file_before_gap_test.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from random import shuffle
import unittest

from podcast_downloader.downloaded import get_last_downloaded_file_before_gap
Expand All @@ -9,7 +10,7 @@ def test_should_return_none_for_empty_collections(self):
result = get_last_downloaded_file_before_gap([], [])

# Assert
self.assertIsNone(result)
self.assertIsNone(result, "On empty directory should be return None")

def test_should_return_none_for_empty_directory_files(self):
# Assign
Expand All @@ -24,7 +25,7 @@ def test_should_return_none_for_empty_directory_files(self):
result = get_last_downloaded_file_before_gap(feed_files, [])

# Assert
self.assertIsNone(result)
self.assertIsNone(result, "On empty directory should be return None")

def test_should_return_last_for_nonempty_directory_files(self):
# Assign
Expand All @@ -41,4 +42,27 @@ def test_should_return_last_for_nonempty_directory_files(self):
result = get_last_downloaded_file_before_gap(feed_files, directory_files)

# Assert
self.assertEqual(result, feed_files[-1])
self.assertEqual(
result, feed_files[-1], "Should return the last files from the feed"
)

def test_should_return_last_according_the_feed_order(self):
# Assign
feed_files = [
"podcast_episode_1.mp3",
"podcast_episode_2.mp3",
"podcast_episode_3.mp3",
"podcast_episode_4.mp3",
]

directory_files = feed_files[0:-1]
shuffle(directory_files)
directory_files = directory_files[:1] + [feed_files[-1]] + directory_files[1:]

# Act
result = get_last_downloaded_file_before_gap(feed_files, directory_files)

# Assert
self.assertEqual(
result, feed_files[-1], "Should return the last files from the feed"
)

0 comments on commit b3bfc21

Please sign in to comment.