Skip to content

Commit

Permalink
E2E: Add test_configuration_http_headers_option
Browse files Browse the repository at this point in the history
  • Loading branch information
dplocki committed Jan 31, 2024
1 parent 738cd47 commit b9493a9
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 5 deletions.
15 changes: 10 additions & 5 deletions e2e/fixures.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from feedgen.feed import FeedGenerator
from pathlib import Path
from pytest_httpserver import HTTPServer
from typing import Dict, Generator, List, Set
from typing import Dict, Generator, Iterable, List, Set


def print_set_content(content: Set):
Expand All @@ -26,6 +26,10 @@ def __init__(self, httpserver: HTTPServer, url_prefix: str = None) -> None:
self.metadata = []
self.httpserver = httpserver
self.url_prefix = url_prefix or ""
self.headers = None

def set_request_headers(self, headers):
self.headers = headers

def add_entry(
self,
Expand Down Expand Up @@ -81,7 +85,7 @@ def __build_rss(self):

for file_name, title, description, published_date, file_type in self.metadata:
self.httpserver.expect_request(
self.url_prefix + "/" + file_name
self.url_prefix + "/" + file_name, headers=self.headers
).respond_with_data("mp3_content")

fe = fg.add_entry()
Expand Down Expand Up @@ -112,9 +116,7 @@ def add_file(self, file_name: str) -> None:
file_path.write_text(file_name + " content")

def is_containing_only(self, expected_files_list: List[str]) -> None:
files_in_destination_directory = set(
file.name for file in self.download_destination_directory.iterdir()
)
files_in_destination_directory = self.get_files_list()
expected_unique_files = set(expected_files_list)

if len(expected_unique_files) > 0:
Expand All @@ -131,6 +133,9 @@ def is_containing_only(self, expected_files_list: List[str]) -> None:

assert len(files_in_destination_directory) == 0

def get_files_list(self) -> Iterable[str]:
return set(file.name for file in self.download_destination_directory.iterdir())

def path(self):
return str(self.download_destination_directory)

Expand Down
41 changes: 41 additions & 0 deletions e2e/test_config_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,44 @@ def test_configuration_downloads_limit_option(
assert (
downloaded_files_count == limit
), f"Excepted the download files number ({downloaded_files_count}) to equal to limit ({limit})"


def test_configuration_http_headers_option(
feed: FeedBuilder,
use_config: Callable[[Dict], None],
podcast_directory_manager: MultiplePodcastDirectory,
):
# Arrange
request_user_agent = generate_random_string()
feed.set_request_headers({"User-Agent": request_user_agent})
feed.add_random_entries()
rss_link = feed.get_feed_url()

use_config(
{
"podcasts": [
{
"name": generate_random_string(),
"http_headers": {"User-Agent": request_user_agent},
"path": podcast_directory_manager.get_first_directory(),
"rss_link": rss_link,
},
{
"name": generate_random_string(),
"path": podcast_directory_manager.get_second_directory(),
"rss_link": rss_link,
},
],
}
)

# Act
run_podcast_downloader()

# Assert
assert (
len(list(podcast_directory_manager.get_first_directory_files())) > 0
), "you need to download something"
assert (
len(list(podcast_directory_manager.get_second_directory_files())) == 0
), "you need to download something"

0 comments on commit b9493a9

Please sign in to comment.