mocked output directory
This commit is contained in:
parent
89eb7bea42
commit
80d0ce0136
2 changed files with 50 additions and 15 deletions
|
|
@ -13,6 +13,7 @@ from typing import Dict
|
||||||
from typing import List
|
from typing import List
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
from typing import Tuple
|
from typing import Tuple
|
||||||
|
from typing import Union
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
import pytest
|
import pytest
|
||||||
|
|
@ -165,19 +166,18 @@ def preset_dict_to_dl_args(preset_dict: Dict) -> str:
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture
|
@pytest.fixture
|
||||||
def preset_dict_to_subscription_yaml_generator() -> Callable:
|
def subscription_yaml_file_generator() -> Callable:
|
||||||
@contextlib.contextmanager
|
@contextlib.contextmanager
|
||||||
def _preset_dict_to_subscription_yaml_generator(subscription_name: str, preset_dict: Dict):
|
def _subscription_yaml_file_generator(yaml_dict: Dict):
|
||||||
subscription_dict = {subscription_name: preset_dict}
|
|
||||||
with tempfile.NamedTemporaryFile(suffix=".yaml", delete=False) as tmp_file:
|
with tempfile.NamedTemporaryFile(suffix=".yaml", delete=False) as tmp_file:
|
||||||
tmp_file.write(json.dumps(subscription_dict).encode("utf-8"))
|
tmp_file.write(json.dumps(yaml_dict).encode("utf-8"))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
yield tmp_file.name
|
yield tmp_file.name
|
||||||
finally:
|
finally:
|
||||||
FileHandler.delete(tmp_file.name)
|
FileHandler.delete(tmp_file.name)
|
||||||
|
|
||||||
return _preset_dict_to_subscription_yaml_generator
|
return _subscription_yaml_file_generator
|
||||||
|
|
||||||
|
|
||||||
###################################################################################################
|
###################################################################################################
|
||||||
|
|
@ -224,8 +224,14 @@ def _load_config(config_path: Path, working_directory: str) -> ConfigFile:
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
def music_video_subscription_path() -> Path:
|
def music_video_subscription_path(
|
||||||
return Path("examples/music_video_subscriptions.yaml")
|
output_directory: str, subscription_yaml_file_generator: Callable
|
||||||
|
) -> Path:
|
||||||
|
yaml = load_yaml("examples/music_video_subscriptions.yaml")
|
||||||
|
yaml["__preset__"]["overrides"]["music_video_directory"] = output_directory
|
||||||
|
|
||||||
|
with subscription_yaml_file_generator(yaml) as mock_filename:
|
||||||
|
yield mock_filename
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
|
|
@ -239,13 +245,25 @@ def tv_show_config(working_directory, tv_show_config_path) -> ConfigFile:
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
def tv_show_subscriptions_path() -> Path:
|
def tv_show_subscriptions_path(
|
||||||
return Path("examples/tv_show_subscriptions.yaml")
|
output_directory: str, subscription_yaml_file_generator: Callable
|
||||||
|
) -> Path:
|
||||||
|
yaml = load_yaml("examples/tv_show_subscriptions.yaml")
|
||||||
|
yaml["__preset__"]["overrides"]["tv_show_directory"] = output_directory
|
||||||
|
|
||||||
|
with subscription_yaml_file_generator(yaml) as mock_filename:
|
||||||
|
yield mock_filename
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
def advanced_tv_show_subscriptions_path() -> Path:
|
def advanced_tv_show_subscriptions_path(
|
||||||
return Path("examples/advanced/tv_show_subscriptions.yaml")
|
output_directory: str, subscription_yaml_file_generator: Callable
|
||||||
|
) -> Path:
|
||||||
|
yaml = load_yaml("examples/advanced/tv_show_subscriptions.yaml")
|
||||||
|
yaml["__preset__"] = {"overrides": {"tv_show_directory": output_directory}}
|
||||||
|
|
||||||
|
with subscription_yaml_file_generator(yaml) as mock_filename:
|
||||||
|
yield mock_filename
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
|
|
@ -265,8 +283,25 @@ def default_config_path(default_config) -> str:
|
||||||
|
|
||||||
|
|
||||||
@pytest.fixture()
|
@pytest.fixture()
|
||||||
def music_subscriptions_path() -> Path:
|
def music_subscriptions_path(
|
||||||
return Path("examples/music_subscriptions.yaml")
|
output_directory: str, subscription_yaml_file_generator: Callable
|
||||||
|
) -> Path:
|
||||||
|
yaml = load_yaml("examples/music_subscriptions.yaml")
|
||||||
|
yaml["__preset__"]["overrides"]["music_directory"] = output_directory
|
||||||
|
|
||||||
|
with subscription_yaml_file_generator(yaml) as mock_filename:
|
||||||
|
yield mock_filename
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.fixture()
|
||||||
|
def docker_default_subscription_path(
|
||||||
|
output_directory: str, subscription_yaml_file_generator: Callable
|
||||||
|
) -> Path:
|
||||||
|
yaml = load_yaml("docker/root/defaults/subscriptions.yaml")
|
||||||
|
yaml["__preset__"]["overrides"]["tv_show_directory"] = output_directory
|
||||||
|
|
||||||
|
with subscription_yaml_file_generator(yaml) as mock_filename:
|
||||||
|
yield mock_filename
|
||||||
|
|
||||||
|
|
||||||
def mock_run_from_cli(args: str) -> List[Subscription]:
|
def mock_run_from_cli(args: str) -> List[Subscription]:
|
||||||
|
|
|
||||||
|
|
@ -540,9 +540,9 @@ def test_music_video_subscriptions(default_config: ConfigFile, music_video_subsc
|
||||||
assert gnr.get("url2").native == "https://www.youtube.com/watch?v=OldpIhHPsbs"
|
assert gnr.get("url2").native == "https://www.youtube.com/watch?v=OldpIhHPsbs"
|
||||||
|
|
||||||
|
|
||||||
def test_default_docker_config_and_subscriptions():
|
def test_default_docker_config_and_subscriptions(docker_default_subscription_path: Path):
|
||||||
default_config = ConfigFile.from_file_path("docker/root/defaults/config.yaml")
|
default_config = ConfigFile.from_file_path("docker/root/defaults/config.yaml")
|
||||||
default_subs = Subscription.from_file_path(
|
default_subs = Subscription.from_file_path(
|
||||||
config=default_config, subscription_path=Path("docker/root/defaults/subscriptions.yaml")
|
config=default_config, subscription_path=docker_default_subscription_path
|
||||||
)
|
)
|
||||||
assert len(default_subs) == 1
|
assert len(default_subs) == 1
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue