Skip to content

Commit

Permalink
Simplified the config configuration in the test
Browse files Browse the repository at this point in the history
  • Loading branch information
dplocki committed Jan 19, 2024
1 parent 825c2b1 commit 2be87ce
Showing 1 changed file with 27 additions and 27 deletions.
54 changes: 27 additions & 27 deletions e2e/test_sample.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from feedgen.feed import FeedGenerator
from pathlib import Path
from typing import Iterator
from pytest_httpserver import HTTPServer
from typing import Callable, Dict, Iterator, List
import datetime
import json
import pytest
Expand All @@ -9,8 +10,6 @@
import subprocess
import sys

from pytest_httpserver import HTTPServer


def generate_random_string(length: int = 7) -> str:
letters = string.ascii_letters
Expand All @@ -27,24 +26,6 @@ def generate_random_sentence(word_count: int) -> str:
)


@pytest.fixture()
def config_file_location():
home_directory = Path.home()
config_file_name = home_directory / ".podcast_downloader_config.json"
backup_config_file_name = (
home_directory / ".safe_copy_podcast_downloader_config.json"
)

if config_file_name.exists():
config_file_name.rename(backup_config_file_name)

yield config_file_name

if backup_config_file_name.exists():
config_file_name.unlink()
backup_config_file_name.rename(config_file_name)


@pytest.fixture()
def download_destination_directory(tmp_path) -> Path:
feed_destination_path = tmp_path / "destination"
Expand Down Expand Up @@ -129,6 +110,9 @@ def __init__(self, download_destination_directory: Path) -> None:
def add_file(self, file_name: str, create_datetime: str):
return self

def is_looking_like(self, files: List[str]) -> bool:
pass

def is_containing(self, file_name: str):
requested_file = self.download_destination_directory / file_name
assert requested_file.exists() and requested_file.is_file()
Expand Down Expand Up @@ -156,8 +140,25 @@ def podcast_directory(download_destination_directory):
yield PodcastDirectory(download_destination_directory)


def build_config(config_path: Path, config_object):
config_path.write_text(json.dumps(config_object))
@pytest.fixture
def use_config():
def internal(config_object: Dict):
config_file_name.write_text(json.dumps(config_object))

home_directory = Path.home()
config_file_name = home_directory / ".podcast_downloader_config.json"
backup_config_file_name = (
home_directory / ".safe_copy_podcast_downloader_config.json"
)

if config_file_name.exists():
config_file_name.rename(backup_config_file_name)

yield internal

if backup_config_file_name.exists():
config_file_name.unlink()
backup_config_file_name.rename(config_file_name)


def run_podcast_downloader():
Expand All @@ -169,8 +170,8 @@ def check_the_download_directory(download_destination_directory: Path) -> Iterat


def test_default_behavior_on_empty_directory(
config_file_location: Path,
feed: FeedBuilder,
use_config: Callable[[Dict], None],
podcast_directory: PodcastDirectory,
):
# Arrange
Expand All @@ -180,8 +181,7 @@ def test_default_behavior_on_empty_directory(
feed.add_entry()
feed.add_entry(file_name=last_file_name)

build_config(
config_file_location,
use_config(
{
"podcasts": [
{
Expand All @@ -190,7 +190,7 @@ def test_default_behavior_on_empty_directory(
"rss_link": feed.get_feed_url(),
}
]
},
}
)

# Act
Expand Down

0 comments on commit 2be87ce

Please sign in to comment.