Files
wookiee-dl/tests/test_cli.py
2022-10-25 11:45:25 -05:00

75 lines
2.5 KiB
Python

import tempfile
from click.testing import CliRunner
from wookiee_dl import cli
import unittest
import shutil
import pathlib
class TestCli(unittest.TestCase):
def setUp(self) -> None:
self.tempfile_directory = tempfile.mkdtemp()
self.runner = CliRunner()
return super().setUp()
def tearDown(self) -> None:
shutil.rmtree(self.tempfile_directory)
return super().tearDown()
def test_cli_001_html_output(self):
"""Output html page, check that the file is created. No checks for contents of file."""
result = self.runner.invoke(
cli.cli,
[
"html",
"--output_directory",
self.tempfile_directory,
"--top_result",
"tarkin family",
],
)
self.assertIsNone(
result.exception, f"Exception encountered {result.output.strip()}"
)
self.assertEqual(
result.exit_code,
0,
f"Exit code not 0 with following output: \n{result.output.strip()}",
)
path = pathlib.Path(result.output.strip())
self.assertEqual((str(path), path.is_file()), (str(path), True))
def test_cli_003_url(self):
"""Print url formatted string."""
result = self.runner.invoke(
cli.cli,
["text", "--format", "url", "--top_result", "tarkin family"],
input="".join(["\n"]),
)
self.assertIsNone(result.exception, f"Exception encountered {result.output}")
self.assertEqual(
result.exit_code,
0,
f"Exit code not 0 with following output: \n{result.output}",
)
self.assertEqual(
"https://starwars.fandom.com/wiki/Tarkin_family", result.output.strip()
)
def test_cli_005_images(self):
"""Dump all images from page to folder. Checks folder was created, no checks for contents of folder."""
result = self.runner.invoke(
cli.cli,
["images", "tarkin family", "-o", self.tempfile_directory, "--top_result"],
input="".join(["\n"]),
)
self.assertIsNone(result.exception, f"Exception encountered {result.output}")
self.assertEqual(
result.exit_code,
0,
f"Exit code not 0 with following output: \n{result.output}",
)
path = pathlib.Path(result.output.strip())
self.assertEqual((str(path), path.is_dir()), (str(path), True))