diff --git a/e2e/fixures.py b/e2e/fixures.py index fe8b118..2e4bcab 100644 --- a/e2e/fixures.py +++ b/e2e/fixures.py @@ -4,7 +4,7 @@ import random import subprocess import sys -from e2e.random import generate_random_sentence, generate_random_string +from e2e.random import generate_random_sentence, generate_random_mp3_file from feedgen.feed import FeedGenerator from pathlib import Path from pytest_httpserver import HTTPServer @@ -26,7 +26,7 @@ def add_entry( description: str = None, ): if file_name == None: - file_name = generate_random_string(7) + ".mp3" + file_name = generate_random_mp3_file() if title == None: title = generate_random_sentence(4) @@ -38,6 +38,12 @@ def add_entry( return self + def add_random_entries(self, n: int = None): + for _ in range(n or random.randint(4, 7)): + self.add_entry() + + return self + def __fill_up_dates(self): result = [] previous = datetime.datetime.now(datetime.timezone.utc) - datetime.timedelta( diff --git a/e2e/random.py b/e2e/random.py index cb7cede..44b6276 100644 --- a/e2e/random.py +++ b/e2e/random.py @@ -1,5 +1,6 @@ import random import string +from typing import Callable, List def generate_random_string(length: int = 7) -> str: @@ -13,3 +14,11 @@ def generate_random_sentence(word_count: int) -> str: ).capitalize() + "." ) + + +def generate_random_mp3_file(): + return generate_random_string() + ".mp3" + + +def call_n_times(generator: Callable[[], str], n: int = None) -> List[str]: + return [generator() for _ in range(n or random.randint(4, 7))] diff --git a/e2e/test_simple_configuration.py b/e2e/test_simple_configuration.py index 7eca115..580c702 100644 --- a/e2e/test_simple_configuration.py +++ b/e2e/test_simple_configuration.py @@ -8,7 +8,7 @@ podcast_directory, download_destination_directory, ) -from e2e.random import generate_random_string +from e2e.random import call_n_times, generate_random_mp3_file, generate_random_string from typing import Callable, Dict @@ -18,10 +18,9 @@ def test_default_behavior_on_empty_podcast_directory( podcast_directory: PodcastDirectory, ): # Arrange - last_file_name = generate_random_string() + ".mp3" + last_file_name = generate_random_mp3_file() - feed.add_entry() - feed.add_entry() + feed.add_random_entries() feed.add_entry(file_name=last_file_name) use_config( @@ -49,18 +48,13 @@ def test_default_behavior_on_nonempty_podcast_directory( podcast_directory: PodcastDirectory, ): # Arrange - podcast_a_file = generate_random_string() + ".mp3" - podcast_b_file = generate_random_string() + ".mp3" - podcast_c_file = generate_random_string() + ".mp3" + podcasts_files = call_n_times(generate_random_mp3_file) - feed.add_entry() - feed.add_entry() - feed.add_entry() - feed.add_entry(file_name=podcast_a_file) - feed.add_entry(file_name=podcast_b_file) - feed.add_entry(file_name=podcast_c_file) + feed.add_random_entries() + for file_name in podcasts_files: + feed.add_entry(file_name=file_name) - podcast_directory.add_file(podcast_a_file) + podcast_directory.add_file(podcasts_files[0]) use_config( { @@ -78,6 +72,4 @@ def test_default_behavior_on_nonempty_podcast_directory( run_podcast_downloader() # Assert - podcast_directory.is_containing_only( - [podcast_a_file, podcast_b_file, podcast_c_file] - ) + podcast_directory.is_containing_only(podcasts_files)