|
| 1 | +import pytest |
| 2 | +from expected_transaction_log import assert_transaction_log_matches |
| 3 | + |
| 4 | +from ytdl_sub.script.utils.exceptions import UserThrownRuntimeError |
| 5 | +from ytdl_sub.subscriptions.subscription import Subscription |
| 6 | + |
| 7 | + |
| 8 | +@pytest.fixture |
| 9 | +def filter_subscription_dict(output_directory): |
| 10 | + return { |
| 11 | + "preset": [ |
| 12 | + "Plex TV Show by Date", |
| 13 | + "Filter Duration", |
| 14 | + ], |
| 15 | + "overrides": {"url": "https://your.name.here", "tv_show_directory": output_directory}, |
| 16 | + } |
| 17 | + |
| 18 | + |
| 19 | +class TestFilterKeywords: |
| 20 | + |
| 21 | + def test_no_overrides( |
| 22 | + self, |
| 23 | + config, |
| 24 | + filter_subscription_dict, |
| 25 | + output_directory, |
| 26 | + subscription_name, |
| 27 | + mock_download_collection_entries, |
| 28 | + ): |
| 29 | + subscription = Subscription.from_dict( |
| 30 | + config=config, |
| 31 | + preset_name=subscription_name, |
| 32 | + preset_dict=filter_subscription_dict, |
| 33 | + ) |
| 34 | + |
| 35 | + with mock_download_collection_entries( |
| 36 | + is_youtube_channel=False, num_urls=1, is_dry_run=True |
| 37 | + ): |
| 38 | + transaction_log = subscription.download(dry_run=True) |
| 39 | + |
| 40 | + assert_transaction_log_matches( |
| 41 | + output_directory=output_directory, |
| 42 | + transaction_log=transaction_log, |
| 43 | + transaction_log_summary_file_name=f"integration/prebuilt_presets/filter_keywords_empty.txt", |
| 44 | + ) |
| 45 | + |
| 46 | + @pytest.mark.parametrize("filter_eval, filter_value, filters_all", |
| 47 | + [ |
| 48 | + ("min", 10, False), |
| 49 | + ("max", 100, False), |
| 50 | + ("min", 100, True), |
| 51 | + ("max", 10, True), |
| 52 | + ] |
| 53 | + ) |
| 54 | + def test_filter_duration( |
| 55 | + self, |
| 56 | + config, |
| 57 | + filter_subscription_dict, |
| 58 | + output_directory, |
| 59 | + subscription_name, |
| 60 | + mock_download_collection_entries, |
| 61 | + filter_eval: str, |
| 62 | + filter_value: int, |
| 63 | + filters_all: bool, |
| 64 | + ): |
| 65 | + filter_subscription_dict["overrides"][f"filter_duration_{filter_eval}_s"] = filter_value |
| 66 | + subscription = Subscription.from_dict( |
| 67 | + config=config, |
| 68 | + preset_name=subscription_name, |
| 69 | + preset_dict=filter_subscription_dict, |
| 70 | + ) |
| 71 | + |
| 72 | + with mock_download_collection_entries( |
| 73 | + is_youtube_channel=False, num_urls=1, is_dry_run=True |
| 74 | + ): |
| 75 | + transaction_log = subscription.download(dry_run=True) |
| 76 | + |
| 77 | + if filters_all: |
| 78 | + assert transaction_log.is_empty |
| 79 | + else: |
| 80 | + assert_transaction_log_matches( |
| 81 | + output_directory=output_directory, |
| 82 | + transaction_log=transaction_log, |
| 83 | + transaction_log_summary_file_name=f"integration/prebuilt_presets/filter_duration.txt", |
| 84 | + ) |
| 85 | + |
| 86 | + |
| 87 | + @pytest.mark.parametrize( |
| 88 | + "filter_eval", |
| 89 | + [ |
| 90 | + "min", |
| 91 | + "max" |
| 92 | + ], |
| 93 | + ) |
| 94 | + def test_error_not_numeric( |
| 95 | + self, |
| 96 | + config, |
| 97 | + filter_subscription_dict, |
| 98 | + output_directory, |
| 99 | + subscription_name, |
| 100 | + mock_download_collection_entries, |
| 101 | + filter_eval, |
| 102 | + ): |
| 103 | + filter_subscription_dict["overrides"][f"filter_duration_{filter_eval}_s"] = "egg" |
| 104 | + subscription = Subscription.from_dict( |
| 105 | + config=config, |
| 106 | + preset_name=subscription_name, |
| 107 | + preset_dict=filter_subscription_dict, |
| 108 | + ) |
| 109 | + |
| 110 | + with ( |
| 111 | + mock_download_collection_entries(is_youtube_channel=False, num_urls=1, is_dry_run=True), |
| 112 | + pytest.raises(UserThrownRuntimeError, match=f"filter_duration args must be numeric"), |
| 113 | + ): |
| 114 | + _ = subscription.download(dry_run=True) |
| 115 | + |
0 commit comments