Skip to content

Commit

Permalink
Add helper random function
Browse files Browse the repository at this point in the history
  • Loading branch information
dplocki committed Jan 21, 2024
1 parent 70b7afd commit 5706fb6
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
10 changes: 8 additions & 2 deletions e2e/fixures.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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(
Expand Down
9 changes: 9 additions & 0 deletions e2e/random.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import random
import string
from typing import Callable, List


def generate_random_string(length: int = 7) -> str:
Expand All @@ -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))]
26 changes: 9 additions & 17 deletions e2e/test_simple_configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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(
Expand Down Expand Up @@ -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(
{
Expand All @@ -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)

0 comments on commit 5706fb6

Please sign in to comment.