2022-05-11 14:22:57 +02:00
|
|
|
import os
|
2022-06-25 01:22:44 +02:00
|
|
|
import platform
|
2022-05-11 14:22:57 +02:00
|
|
|
import shutil
|
2022-06-25 14:40:41 +02:00
|
|
|
import time
|
2022-05-11 14:22:57 +02:00
|
|
|
from pathlib import Path
|
2022-05-13 22:34:25 +02:00
|
|
|
|
2022-06-25 14:40:41 +02:00
|
|
|
import pytest
|
2023-07-02 16:40:09 +02:00
|
|
|
from pytest import MonkeyPatch
|
2022-06-25 14:40:41 +02:00
|
|
|
|
2023-02-13 23:17:52 +01:00
|
|
|
from mangadlp import app
|
2022-05-11 14:22:57 +02:00
|
|
|
|
|
|
|
|
2022-06-25 14:40:41 +02:00
|
|
|
@pytest.fixture
|
2023-07-02 16:45:33 +02:00
|
|
|
def wait_10s():
|
2022-06-25 14:40:41 +02:00
|
|
|
print("sleeping 10 seconds because of api timeouts")
|
|
|
|
time.sleep(10)
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture
|
2023-07-02 16:45:33 +02:00
|
|
|
def wait_20s():
|
2022-06-25 14:40:41 +02:00
|
|
|
print("sleeping 20 seconds because of api timeouts")
|
|
|
|
time.sleep(20)
|
|
|
|
|
|
|
|
|
2023-07-02 16:40:09 +02:00
|
|
|
def test_full_api_mangadex(wait_20s: MonkeyPatch):
|
2023-02-15 20:17:22 +01:00
|
|
|
manga_path = Path("tests/Tomo-chan wa Onna no ko")
|
2023-07-02 16:40:09 +02:00
|
|
|
chapter_path = Path("tests/Tomo-chan wa Onna no ko/Ch. 1 - Once In A Life Time Misfire.cbz")
|
2022-05-16 22:03:37 +02:00
|
|
|
mdlp = app.MangaDLP(
|
2023-02-15 20:17:22 +01:00
|
|
|
url_uuid="https://mangadex.org/title/76ee7069-23b4-493c-bc44-34ccbf3051a8/tomo-chan-wa-onna-no-ko",
|
2022-05-13 22:34:25 +02:00
|
|
|
language="en",
|
|
|
|
chapters="1",
|
|
|
|
list_chapters=False,
|
|
|
|
file_format="cbz",
|
|
|
|
forcevol=False,
|
|
|
|
download_path="tests",
|
2022-06-25 14:28:42 +02:00
|
|
|
download_wait=2,
|
2022-05-11 14:22:57 +02:00
|
|
|
)
|
2022-05-25 22:18:23 +02:00
|
|
|
mdlp.get_manga()
|
2022-05-11 14:22:57 +02:00
|
|
|
|
2022-05-13 22:34:25 +02:00
|
|
|
assert manga_path.exists() and manga_path.is_dir()
|
|
|
|
assert chapter_path.exists() and chapter_path.is_file()
|
2022-05-11 14:22:57 +02:00
|
|
|
# cleanup
|
|
|
|
shutil.rmtree(manga_path, ignore_errors=True)
|
|
|
|
|
|
|
|
|
2023-07-02 16:40:09 +02:00
|
|
|
def test_full_with_input_cbz(wait_20s: MonkeyPatch):
|
|
|
|
url_uuid = (
|
|
|
|
"https://mangadex.org/title/76ee7069-23b4-493c-bc44-34ccbf3051a8/tomo-chan-wa-onna-no-ko"
|
|
|
|
)
|
2022-05-13 22:34:25 +02:00
|
|
|
language = "en"
|
2022-05-11 14:22:57 +02:00
|
|
|
chapters = "1"
|
2022-05-16 16:09:17 +02:00
|
|
|
file_format = "cbz"
|
2022-05-11 14:22:57 +02:00
|
|
|
download_path = "tests"
|
2023-02-15 20:17:22 +01:00
|
|
|
manga_path = Path("tests/Tomo-chan wa Onna no ko")
|
2023-07-02 16:40:09 +02:00
|
|
|
chapter_path = Path("tests/Tomo-chan wa Onna no ko/Ch. 1 - Once In A Life Time Misfire.cbz")
|
2022-06-26 15:23:19 +02:00
|
|
|
command_args = f"-u {url_uuid} -l {language} -c {chapters} --path {download_path} --format {file_format} --debug --wait 2"
|
2022-05-11 14:22:57 +02:00
|
|
|
script_path = "manga-dlp.py"
|
|
|
|
os.system(f"python3 {script_path} {command_args}")
|
|
|
|
|
2022-05-13 22:34:25 +02:00
|
|
|
assert manga_path.exists() and manga_path.is_dir()
|
|
|
|
assert chapter_path.exists() and chapter_path.is_file()
|
2022-05-11 14:22:57 +02:00
|
|
|
# cleanup
|
|
|
|
shutil.rmtree(manga_path, ignore_errors=True)
|
|
|
|
|
|
|
|
|
2023-07-02 16:40:09 +02:00
|
|
|
def test_full_with_input_cbz_info(wait_20s: MonkeyPatch):
|
|
|
|
url_uuid = (
|
|
|
|
"https://mangadex.org/title/76ee7069-23b4-493c-bc44-34ccbf3051a8/tomo-chan-wa-onna-no-ko"
|
|
|
|
)
|
2022-07-14 15:20:08 +02:00
|
|
|
language = "en"
|
|
|
|
chapters = "1"
|
|
|
|
file_format = "cbz"
|
|
|
|
download_path = "tests"
|
2023-02-15 20:17:22 +01:00
|
|
|
manga_path = Path("tests/Tomo-chan wa Onna no ko")
|
2023-07-02 16:40:09 +02:00
|
|
|
chapter_path = Path("tests/Tomo-chan wa Onna no ko/Ch. 1 - Once In A Life Time Misfire.cbz")
|
2022-07-14 15:20:08 +02:00
|
|
|
command_args = f"-u {url_uuid} -l {language} -c {chapters} --path {download_path} --format {file_format} --wait 2"
|
|
|
|
script_path = "manga-dlp.py"
|
|
|
|
os.system(f"python3 {script_path} {command_args}")
|
|
|
|
|
|
|
|
assert manga_path.exists() and manga_path.is_dir()
|
|
|
|
assert chapter_path.exists() and chapter_path.is_file()
|
|
|
|
# cleanup
|
|
|
|
shutil.rmtree(manga_path, ignore_errors=True)
|
|
|
|
|
|
|
|
|
2023-07-02 16:40:09 +02:00
|
|
|
@pytest.mark.skipif(platform.machine() != "x86_64", reason="pdf only supported on amd64")
|
|
|
|
def test_full_with_input_pdf(wait_20s: MonkeyPatch):
|
|
|
|
url_uuid = (
|
|
|
|
"https://mangadex.org/title/76ee7069-23b4-493c-bc44-34ccbf3051a8/tomo-chan-wa-onna-no-ko"
|
|
|
|
)
|
2022-05-16 16:09:17 +02:00
|
|
|
language = "en"
|
|
|
|
chapters = "1"
|
|
|
|
file_format = "pdf"
|
|
|
|
download_path = "tests"
|
2023-02-15 20:17:22 +01:00
|
|
|
manga_path = Path("tests/Tomo-chan wa Onna no ko")
|
2023-07-02 16:40:09 +02:00
|
|
|
chapter_path = Path("tests/Tomo-chan wa Onna no ko/Ch. 1 - Once In A Life Time Misfire.pdf")
|
2022-06-26 15:23:19 +02:00
|
|
|
command_args = f"-u {url_uuid} -l {language} -c {chapters} --path {download_path} --format {file_format} --debug --wait 2"
|
2022-05-11 14:22:57 +02:00
|
|
|
script_path = "manga-dlp.py"
|
2022-05-16 16:09:17 +02:00
|
|
|
os.system(f"python3 {script_path} {command_args}")
|
|
|
|
|
|
|
|
assert manga_path.exists() and manga_path.is_dir()
|
|
|
|
assert chapter_path.exists() and chapter_path.is_file()
|
|
|
|
# cleanup
|
|
|
|
shutil.rmtree(manga_path, ignore_errors=True)
|
|
|
|
|
|
|
|
|
2023-07-02 16:40:09 +02:00
|
|
|
def test_full_with_input_folder(wait_20s: MonkeyPatch):
|
|
|
|
url_uuid = (
|
|
|
|
"https://mangadex.org/title/76ee7069-23b4-493c-bc44-34ccbf3051a8/tomo-chan-wa-onna-no-ko"
|
|
|
|
)
|
2022-05-16 16:09:17 +02:00
|
|
|
language = "en"
|
|
|
|
chapters = "1"
|
|
|
|
file_format = ""
|
|
|
|
download_path = "tests"
|
2023-02-15 20:17:22 +01:00
|
|
|
manga_path = Path("tests/Tomo-chan wa Onna no ko")
|
2023-07-02 16:40:09 +02:00
|
|
|
chapter_path = Path("tests/Tomo-chan wa Onna no ko/Ch. 1 - Once In A Life Time Misfire")
|
2023-02-15 20:17:22 +01:00
|
|
|
metadata_path = Path(
|
|
|
|
"tests/Tomo-chan wa Onna no ko/Ch. 1 - Once In A Life Time Misfire/ComicInfo.xml"
|
|
|
|
)
|
2022-06-26 15:23:19 +02:00
|
|
|
command_args = f"-u {url_uuid} -l {language} -c {chapters} --path {download_path} --format '{file_format}' --debug --wait 2"
|
2022-05-16 16:09:17 +02:00
|
|
|
script_path = "manga-dlp.py"
|
|
|
|
os.system(f"python3 {script_path} {command_args}")
|
|
|
|
|
|
|
|
assert manga_path.exists() and manga_path.is_dir()
|
|
|
|
assert chapter_path.exists() and chapter_path.is_dir()
|
2023-02-13 23:17:52 +01:00
|
|
|
assert metadata_path.exists() and metadata_path.is_file()
|
2022-05-16 16:09:17 +02:00
|
|
|
# cleanup
|
|
|
|
shutil.rmtree(manga_path, ignore_errors=True)
|
|
|
|
|
|
|
|
|
2023-07-02 16:40:09 +02:00
|
|
|
def test_full_with_input_skip_cbz(wait_10s: MonkeyPatch):
|
|
|
|
url_uuid = (
|
|
|
|
"https://mangadex.org/title/76ee7069-23b4-493c-bc44-34ccbf3051a8/tomo-chan-wa-onna-no-ko"
|
|
|
|
)
|
2022-05-16 16:09:17 +02:00
|
|
|
language = "en"
|
|
|
|
chapters = "1"
|
|
|
|
file_format = "cbz"
|
|
|
|
download_path = "tests"
|
2023-02-15 20:17:22 +01:00
|
|
|
manga_path = Path("tests/Tomo-chan wa Onna no ko")
|
2023-07-02 16:40:09 +02:00
|
|
|
chapter_path = Path("tests/Tomo-chan wa Onna no ko/Ch. 1 - Once In A Life Time Misfire.cbz")
|
2022-06-26 15:23:19 +02:00
|
|
|
command_args = f"-u {url_uuid} -l {language} -c {chapters} --path {download_path} --format {file_format} --debug --wait 2"
|
2022-05-16 16:09:17 +02:00
|
|
|
script_path = "manga-dlp.py"
|
|
|
|
manga_path.mkdir(parents=True, exist_ok=True)
|
|
|
|
chapter_path.touch()
|
|
|
|
|
|
|
|
os.system(f"python3 {script_path} {command_args}")
|
|
|
|
assert chapter_path.is_file()
|
|
|
|
assert chapter_path.stat().st_size == 0
|
|
|
|
# cleanup
|
|
|
|
shutil.rmtree(manga_path, ignore_errors=True)
|
|
|
|
|
|
|
|
|
2023-07-02 16:40:09 +02:00
|
|
|
def test_full_with_input_skip_folder(wait_10s: MonkeyPatch):
|
|
|
|
url_uuid = (
|
|
|
|
"https://mangadex.org/title/76ee7069-23b4-493c-bc44-34ccbf3051a8/tomo-chan-wa-onna-no-ko"
|
|
|
|
)
|
2022-05-16 16:09:17 +02:00
|
|
|
language = "en"
|
|
|
|
chapters = "1"
|
|
|
|
file_format = ""
|
|
|
|
download_path = "tests"
|
2023-02-15 20:17:22 +01:00
|
|
|
manga_path = Path("tests/Tomo-chan wa Onna no ko")
|
2023-07-02 16:40:09 +02:00
|
|
|
chapter_path = Path("tests/Tomo-chan wa Onna no ko/Ch. 1 - Once In A Life Time Misfire")
|
2022-06-26 15:23:19 +02:00
|
|
|
command_args = f"-u {url_uuid} -l {language} -c {chapters} --path {download_path} --format '{file_format}' --debug --wait 2"
|
2022-05-16 16:09:17 +02:00
|
|
|
script_path = "manga-dlp.py"
|
|
|
|
chapter_path.mkdir(parents=True, exist_ok=True)
|
|
|
|
|
|
|
|
os.system(f"python3 {script_path} {command_args}")
|
2023-07-02 16:40:09 +02:00
|
|
|
found_files: list[str] = []
|
2022-05-16 16:09:17 +02:00
|
|
|
for file in chapter_path.iterdir():
|
|
|
|
found_files.append(file.name)
|
|
|
|
|
|
|
|
assert chapter_path.is_dir()
|
|
|
|
assert found_files == []
|
2023-02-15 20:17:22 +01:00
|
|
|
assert not Path(
|
|
|
|
"tests/Tomo-chan wa Onna no ko/Ch. 1 - Once In A Life Time Misfire.cbz"
|
|
|
|
).exists()
|
|
|
|
assert not Path(
|
|
|
|
"tests/Tomo-chan wa Onna no ko/Ch. 1 - Once In A Life Time Misfire.zip"
|
|
|
|
).exists()
|
2022-05-16 16:09:17 +02:00
|
|
|
# cleanup
|
|
|
|
shutil.rmtree(manga_path, ignore_errors=True)
|
|
|
|
|
|
|
|
|
2023-07-02 16:40:09 +02:00
|
|
|
def test_full_with_read_cbz(wait_20s: MonkeyPatch):
|
2022-05-16 16:09:17 +02:00
|
|
|
url_list = Path("tests/test_list2.txt")
|
|
|
|
language = "en"
|
|
|
|
chapters = "1"
|
|
|
|
file_format = "cbz"
|
|
|
|
download_path = "tests"
|
2023-02-15 20:17:22 +01:00
|
|
|
manga_path = Path("tests/Tomo-chan wa Onna no ko")
|
2023-07-02 16:40:09 +02:00
|
|
|
chapter_path = Path("tests/Tomo-chan wa Onna no ko/Ch. 1 - Once In A Life Time Misfire.cbz")
|
|
|
|
command_args = f"--read {url_list!s} -l {language} -c {chapters} --path {download_path} --format {file_format} --debug --wait 2"
|
2022-05-16 16:09:17 +02:00
|
|
|
script_path = "manga-dlp.py"
|
|
|
|
url_list.write_text(
|
2023-02-15 20:17:22 +01:00
|
|
|
"https://mangadex.org/title/76ee7069-23b4-493c-bc44-34ccbf3051a8/tomo-chan-wa-onna-no-ko"
|
2022-05-16 16:09:17 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
os.system(f"python3 {script_path} {command_args}")
|
|
|
|
|
|
|
|
assert manga_path.exists() and manga_path.is_dir()
|
|
|
|
assert chapter_path.exists() and chapter_path.is_file()
|
|
|
|
# cleanup
|
|
|
|
shutil.rmtree(manga_path, ignore_errors=True)
|
|
|
|
|
|
|
|
|
2023-07-02 16:40:09 +02:00
|
|
|
def test_full_with_read_skip_cbz(wait_10s: MonkeyPatch):
|
2022-05-16 16:09:17 +02:00
|
|
|
url_list = Path("tests/test_list2.txt")
|
|
|
|
language = "en"
|
|
|
|
chapters = "1"
|
|
|
|
file_format = "cbz"
|
|
|
|
download_path = "tests"
|
2023-02-15 20:17:22 +01:00
|
|
|
manga_path = Path("tests/Tomo-chan wa Onna no ko")
|
2023-07-02 16:40:09 +02:00
|
|
|
chapter_path = Path("tests/Tomo-chan wa Onna no ko/Ch. 1 - Once In A Life Time Misfire.cbz")
|
|
|
|
command_args = f"--read {url_list!s} -l {language} -c {chapters} --path {download_path} --format {file_format} --debug --wait 2"
|
2022-05-16 16:09:17 +02:00
|
|
|
script_path = "manga-dlp.py"
|
|
|
|
manga_path.mkdir(parents=True, exist_ok=True)
|
|
|
|
chapter_path.touch()
|
|
|
|
url_list.write_text(
|
2023-02-15 20:17:22 +01:00
|
|
|
"https://mangadex.org/title/76ee7069-23b4-493c-bc44-34ccbf3051a8/tomo-chan-wa-onna-no-ko"
|
2022-05-16 16:09:17 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
os.system(f"python3 {script_path} {command_args}")
|
|
|
|
assert chapter_path.is_file()
|
|
|
|
assert chapter_path.stat().st_size == 0
|
|
|
|
# cleanup
|
|
|
|
shutil.rmtree(manga_path, ignore_errors=True)
|
|
|
|
|
|
|
|
|
|
|
|
# def test_full_without_input():
|
|
|
|
# script_path = "manga-dlp.py"
|
|
|
|
# assert os.system(f"python3 {script_path}") != 0
|
2022-05-13 22:34:25 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_full_show_version():
|
|
|
|
script_path = "manga-dlp.py"
|
|
|
|
assert os.system(f"python3 {script_path} --version") == 0
|