Bulk asynchronous downloader for multiple file hosts
Python asynciobunkrcyberdropdownloaderdropboxfilestergofilegoogle-drivemediafiremegamega-nzonedrivepatreonpawchivepinterestpixeldraintransfer-ittwitchtwittervk
ci/cd: update tests (#734)
NTFSvolume3206bc162e4c
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.ymlindex a78cdfe4b..7c7c3f9eb 100644--- a/.github/workflows/ci.yml+++ b/.github/workflows/ci.yml@@ -11,8 +11,6 @@ on:jobs:test:- env:- APPRISE_TEST_EMAIL_URL: ${{ secrets.APPRISE_TEST_EMAIL_URL }}runs-on: ${{ matrix.os }}strategy:@@ -42,4 +40,31 @@ jobs:- name: Run pytestrun: |- poetry run pytest -v --cov+ poetry run pytest -v --cov --ignore=tests/test_apprise.py++ test_apprise:+ env:+ APPRISE_TEST_EMAIL_URL: ${{ secrets.APPRISE_TEST_EMAIL_URL }}+ runs-on: ubuntu-latest++ steps:+ - name: Checkout code+ uses: actions/checkout@v4++ - name: Set up Python 3.11+ uses: actions/setup-python@v5+ with:+ python-version: 3.11++ - name: Install Poetry+ run: |+ curl -sSL https://install.python-poetry.org | python3 -+ export PATH="$HOME/.poetry/bin:$PATH"++ - name: Install dependencies+ run: |+ poetry install++ - name: Run pytest+ run: |+ poetry run pytest --covdiff --git a/cyberdrop_dl/utils/apprise.py b/cyberdrop_dl/utils/apprise.pyindex 3f826e9be..97dac0a98 100644--- a/cyberdrop_dl/utils/apprise.py+++ b/cyberdrop_dl/utils/apprise.py@@ -2,6 +2,7 @@ from __future__ import annotationsimport jsonimport shutil+import sysimport tempfilefrom dataclasses import dataclassfrom enum import IntEnum@@ -89,6 +90,7 @@ def get_apprise_urls(*, file: Path | None = None, urls: list[str] | None = None)except ValidationError as e:handle_validation_error(e, title="Apprise", file=file)+ sys.exit(1)def _simplify_urls(apprise_urls: list[AppriseURLModel]) -> list[AppriseURL]:@@ -194,6 +196,7 @@ async def send_apprise_notifications(manager: Manager) -> tuple[constants.Notifimain_log = manager.path_manager.main_log.resolve()results = {}all_urls = [x.raw_url for x in apprise_urls]+ log_lines = []with (apprise.LogCapture(level=10, fmt="%(levelname)-7s - %(message)s") as capture,@@ -207,6 +210,7 @@ async def send_apprise_notifications(manager: Manager) -> tuple[constants.Notifi"simplified": {},}attach_file_failed_msg = "Unable to get copy of main log file. 'attach_logs' URLs will be proccessed without it"+ log_lines = [LogLine(LogLevel.ERROR, attach_file_failed_msg)]try:shutil.copy(main_log, temp_main_log)notifications_to_send["attach_logs"]["attach"] = str(temp_main_log.resolve())@@ -218,4 +222,5 @@ async def send_apprise_notifications(manager: Manager) -> tuple[constants.Notifiresults[tag] = await apprise_obj.async_notify(**msg, tag=tag)apprise_logs = capture.getvalue()- return _process_results(all_urls, results, apprise_logs)+ result, new_log_lines = _process_results(all_urls, results, apprise_logs)+ return result, log_lines + new_log_linesdiff --git a/tests/test_apprise.py b/tests/test_apprise.pyindex 535fe052f..4e98e83e1 100644--- a/tests/test_apprise.py+++ b/tests/test_apprise.py@@ -1,17 +1,19 @@+import inspectimport osfrom dataclasses import dataclass, fieldfrom pathlib import Pathimport pytest+from rich.text import Textfrom cyberdrop_dl.managers.config_manager import ConfigManagerfrom cyberdrop_dl.managers.manager import Managerfrom cyberdrop_dl.managers.path_manager import PathManager-from cyberdrop_dl.utils import apprise+from cyberdrop_dl.utils import apprise, constantsfrom cyberdrop_dl.utils.constants import NotificationResultfrom tests.fake_classes.managers import FakeCacheManager-TEST_FILES_PATH = Path("tests/test_files/apprise")+TEST_FILES_PATH = Path(__file__).parent / "test_files/apprise"FAKE_MANAGER = Manager()FAKE_MANAGER.cache_manager = FakeCacheManager(FAKE_MANAGER)FAKE_MANAGER.config_manager = ConfigManager(FAKE_MANAGER)@@ -28,6 +30,7 @@ class AppriseTestCase:include: list[str] = field(default_factory=list)exclude: list[str] = field(default_factory=list)file: Path | None = None+ name: str = "Testing Apprise"def test_get_apprise_urls():@@ -74,12 +77,13 @@ def test_get_apprise_urls():async def send_notification(test_case: AppriseTestCase):- assert URL_SUCCESS, "Email URL should be set on enviroment"+ assert URL_SUCCESS, "Apprise URL should be set on enviroment"FAKE_MANAGER.config_manager.apprise_urls = []if test_case.urls and any(test_case.urls):FAKE_MANAGER.config_manager.apprise_urls = apprise.get_apprise_urls(urls=test_case.urls)FAKE_MANAGER.path_manager = PathManager(FAKE_MANAGER)FAKE_MANAGER.path_manager.main_log = test_case.file or TEST_FILES_PATH / "valid_single_url.txt"+ constants.LOG_OUTPUT_TEXT = Text(test_case.name)result, logs = await apprise.send_apprise_notifications(FAKE_MANAGER)assert result.value == test_case.result.value, f"Result for this case should be {test_case.result.value}"assert isinstance(logs, list), "Invalid return type for logs"@@ -94,7 +98,11 @@ async def send_notification(test_case: AppriseTestCase):async def test_failed_notification():- test_case = AppriseTestCase(urls=[URL_FAIL], result=NotificationResult.FAILED)+ test_case = AppriseTestCase(+ urls=[URL_FAIL],+ result=NotificationResult.FAILED,+ name=inspect.currentframe().f_code.co_name, # type: ignore+ )await send_notification(test_case)@@ -102,8 +110,8 @@ async def test_successful_notification():test_case = AppriseTestCase(urls=[URL_SUCCESS],result=NotificationResult.SUCCESS,- include=["Sent Email to"],- exclude=["Preparing Email attachment"],+ include=["Sent Discord notification", "Discord Payload"],+ name=inspect.currentframe().f_code.co_name, # type: ignore)await send_notification(test_case)@@ -112,7 +120,8 @@ async def test_successful_notification_with_successful_attachment():test_case = AppriseTestCase(urls=[URL_SUCCESS_ATTACH_LOGS],result=NotificationResult.SUCCESS,- include=["Sent Email to", "Preparing Email attachment"],+ include=["Sent Discord notification", "Discord Payload"],+ name=inspect.currentframe().f_code.co_name, # type: ignore)await send_notification(test_case)@@ -121,22 +130,28 @@ async def test_successful_notification_with_failed_attachment():test_case = AppriseTestCase(urls=[URL_SUCCESS_ATTACH_LOGS],result=NotificationResult.SUCCESS,- include=["Sent Email to"],- exclude=["Preparing Email attachment"],+ include=["Sent Discord notification", "Discord Payload", "Unable to get copy of main log file"],file=TEST_FILES_PATH / "file_that_does_exists.txt",+ name=inspect.currentframe().f_code.co_name, # type: ignore)await send_notification(test_case)async def test_none_notification():test_case = AppriseTestCase(- urls=[""], result=NotificationResult.NONE, include=[NotificationResult.NONE.value.plain]+ urls=[""],+ result=NotificationResult.NONE,+ include=[NotificationResult.NONE.value.plain],+ name=inspect.currentframe().f_code.co_name, # type: ignore)await send_notification(test_case)async def test_partial_notification():test_case = AppriseTestCase(- urls=[URL_SUCCESS_ATTACH_LOGS, URL_FAIL], result=NotificationResult.PARTIAL, include=["Sent Email to"]+ urls=[URL_SUCCESS_ATTACH_LOGS, URL_FAIL],+ result=NotificationResult.PARTIAL,+ include=["Connection error while submitting email", "Sent Discord notification"],+ name=inspect.currentframe().f_code.co_name, # type: ignore)await send_notification(test_case)