cleantoots/tests/test_cli.py

74 lines
2.6 KiB
Python
Raw Permalink Normal View History

2019-12-28 00:37:19 +01:00
import os
2019-12-27 22:33:39 +01:00
import unittest
2019-12-28 00:37:19 +01:00
from click.testing import CliRunner
2019-12-27 22:33:39 +01:00
2019-12-28 00:37:19 +01:00
from cleantoots.main import cli
class SetupConfigTestCase(unittest.TestCase):
def setUp(self) -> None:
self.runner = CliRunner()
def test_setup_config(self):
with self.runner.isolated_filesystem():
2019-12-28 10:42:02 +01:00
result = self.runner.invoke(cli, ["-d", ".", "config", "setup"])
2021-12-19 14:21:43 +01:00
assert result.exit_code == 0
assert "config.ini written" in result.output
assert os.path.isfile(os.path.join(".", "config.ini"))
2019-12-28 00:37:19 +01:00
def test_setup_config_twice_fails(self):
with self.runner.isolated_filesystem():
2019-12-28 10:42:02 +01:00
self.runner.invoke(cli, ["-d", ".", "config", "setup"])
2021-12-19 14:21:43 +01:00
assert os.path.isfile(os.path.join(".", "config.ini"))
2019-12-28 10:42:02 +01:00
result = self.runner.invoke(cli, ["-d", ".", "config", "setup"])
2021-12-19 14:21:43 +01:00
assert result.exit_code == 0
assert "Not touching anything" in result.output
assert "cleantoots config edit" in result.output
2019-12-28 00:37:19 +01:00
def test_config_output(self):
with self.runner.isolated_filesystem():
2019-12-28 10:42:02 +01:00
self.runner.invoke(cli, ["-d", ".", "config", "setup"])
result = self.runner.invoke(cli, ["-d", ".", "config", "list"])
2019-12-28 00:37:19 +01:00
expected = [
"Mastodon.social",
"api_base_url",
"app_secret_file",
"user_secret_file",
"protected_toots",
"boost_limit",
"favorite_limit",
"days_count",
"timezone",
]
for exp in expected:
2021-12-19 14:21:43 +01:00
assert exp in result.output
2019-12-28 00:37:19 +01:00
2019-12-28 10:42:02 +01:00
def test_config_list_no_file(self):
with self.runner.isolated_filesystem():
result = self.runner.invoke(cli, ["-d", ".", "config", "list"])
2021-12-19 14:21:43 +01:00
assert "cleantoots config setup" in result.output
assert result.exit_code == 0
2019-12-28 10:42:02 +01:00
def test_config_edit_no_file(self):
with self.runner.isolated_filesystem():
result = self.runner.invoke(cli, ["-d", ".", "config", "edit"])
2021-12-19 14:21:43 +01:00
assert "cleantoots config setup" in result.output
assert result.exit_code == 0
2019-12-28 10:42:02 +01:00
2019-12-28 00:37:19 +01:00
def test_login_output(self):
with self.runner.isolated_filesystem():
2019-12-28 10:42:02 +01:00
self.runner.invoke(cli, ["-d", ".", "config", "setup"])
result = self.runner.invoke(
cli, ["-d", ".", "config", "login"], input="\nFAKECODE"
)
2021-12-19 14:21:43 +01:00
assert "Enter code for" in result.output
2019-12-27 22:33:39 +01:00
2019-12-28 13:31:34 +01:00
def test_clean_exists(self):
result = self.runner.invoke(cli, ["-d", ".", "clean"])
2021-12-19 14:21:43 +01:00
assert result.exit_code == 0
2019-12-28 13:31:34 +01:00
2019-12-27 22:33:39 +01:00
if __name__ == "__main__":
unittest.main()