1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
|
import unittest
from unittest.mock import patch, MagicMock
from firefly_cli import cli
class TestCli(unittest.TestCase):
@patch("firefly_cli.cli.config.load")
@patch("firefly_cli.cli.Client")
def test_dispatches_account_list(self, Client, load):
load.return_value = {"url": "https://f", "token": "t"}
Client.return_value.request.return_value = {"data": []}
rc = cli.main(["account", "list"])
self.assertEqual(rc, 0)
@patch("firefly_cli.cli.config.load")
def test_config_error_returns_nonzero(self, load):
from firefly_cli.errors import ConfigError
load.side_effect = ConfigError("no config")
rc = cli.main(["account", "list"])
self.assertEqual(rc, 1)
def test_auth_set_does_not_require_config(self):
# auth set must run even with no config/client
with patch("firefly_cli.cli.config.write") as w:
w.return_value = "/tmp/x"
rc = cli.main(["auth", "set", "--url", "https://f", "--token", "t"])
self.assertEqual(rc, 0)
def test_every_command_group_has_a_help_blurb(self):
# Every group shown in `firefly --help` should carry a _GROUP_HELP
# blurb; a new group added without one is easy to miss (budget did).
from firefly_cli import registry
import firefly_cli.commands # noqa: F401 ensure registration
groups = {c.name.split(" ", 1)[0] for c in registry.all_commands()}
missing = groups - set(cli._GROUP_HELP)
self.assertFalse(missing, f"groups without _GROUP_HELP: {missing}")
|