Skip to content

Commit

Permalink
test: add test_download_post
Browse files Browse the repository at this point in the history
  • Loading branch information
Ljzd-PRO committed Nov 9, 2023
1 parent 83955f1 commit 8e69269
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions tests/ktoolbox/test_cli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import tempfile
from collections import OrderedDict
from pathlib import Path
from typing import NamedTuple
Expand All @@ -10,7 +11,9 @@
from ktoolbox import __version__
from ktoolbox.api.model import Creator, Post
from ktoolbox.cli import KToolBoxCli
from ktoolbox.enum import TextEnum, DataStorageNameEnum
from ktoolbox.model import SearchResult
from ktoolbox.utils import generate_msg
from tests.utils import settings


Expand Down Expand Up @@ -91,3 +94,33 @@ async def test_get_post():

normal = await KToolBoxCli.get_post("fanbox", "3316400", "6434459")
assert isinstance(normal, Post)


@pytest.mark.asyncio
async def test_download_post():
invalid = await KToolBoxCli.download_post(url="")
assert invalid == generate_msg(
TextEnum.MissingParams.value,
use_at_lease_one=[
["url"],
["service", "creator_id", "post_id"]
]
)

with tempfile.TemporaryDirectory() as td:
dir_path = Path(td)
url_only = await KToolBoxCli.download_post(
url="https://kemono.su/fanbox/user/9016/post/6622968",
path=dir_path
)
assert url_only is None
assert (dir_new := next(dir_path.iterdir(), None)) is not None
assert (dir_new / DataStorageNameEnum.PostData.value).is_file()

no_url_and_no_dump = await KToolBoxCli.download_post(
service="fanbox",
creator_id="9016",
post_id="6622968",
dump_post_data=False
)
assert no_url_and_no_dump is None

0 comments on commit 8e69269

Please sign in to comment.