2021-12-12 16:35:26 -05:00
|
|
|
import typing as t
|
|
|
|
import unittest
|
|
|
|
from unittest import mock
|
|
|
|
|
|
|
|
from click.testing import CliRunner
|
|
|
|
|
|
|
|
from aprsd import config as aprsd_config
|
|
|
|
from aprsd.aprsd import cli
|
|
|
|
from aprsd.cmds import dev # noqa
|
|
|
|
|
|
|
|
|
|
|
|
F = t.TypeVar("F", bound=t.Callable[..., t.Any])
|
|
|
|
|
|
|
|
|
|
|
|
class TestDevTestPluginCommand(unittest.TestCase):
|
|
|
|
|
|
|
|
def _build_config(self, login=None, password=None):
|
2022-07-20 08:43:57 -04:00
|
|
|
config = {
|
|
|
|
"aprs": {},
|
2022-12-14 22:03:21 -05:00
|
|
|
"aprsd": {
|
|
|
|
"trace": False,
|
|
|
|
"watch_list": {},
|
|
|
|
},
|
2022-07-20 08:43:57 -04:00
|
|
|
}
|
2021-12-12 16:35:26 -05:00
|
|
|
if login:
|
|
|
|
config["aprs"]["login"] = login
|
|
|
|
|
|
|
|
if password:
|
|
|
|
config["aprs"]["password"] = password
|
|
|
|
|
|
|
|
return aprsd_config.Config(config)
|
|
|
|
|
|
|
|
@mock.patch("aprsd.config.parse_config")
|
2022-07-07 11:02:43 -04:00
|
|
|
@mock.patch("aprsd.logging.log.setup_logging")
|
2021-12-12 16:35:26 -05:00
|
|
|
def test_no_login(self, mock_logging, mock_parse_config):
|
|
|
|
"""Make sure we get an error if there is no login and config."""
|
|
|
|
|
|
|
|
runner = CliRunner()
|
|
|
|
mock_parse_config.return_value = self._build_config()
|
|
|
|
|
|
|
|
result = runner.invoke(
|
2022-12-14 22:03:21 -05:00
|
|
|
cli, [
|
|
|
|
"dev", "test-plugin",
|
|
|
|
"-p", "aprsd.plugins.version.VersionPlugin",
|
|
|
|
"bogus command",
|
|
|
|
],
|
2021-12-12 16:35:26 -05:00
|
|
|
catch_exceptions=False,
|
|
|
|
)
|
|
|
|
# rich.print(f"EXIT CODE {result.exit_code}")
|
|
|
|
# rich.print(f"Exception {result.exception}")
|
|
|
|
# rich.print(f"OUTPUT {result.output}")
|
|
|
|
assert result.exit_code == -1
|
|
|
|
assert "Must set --aprs_login or APRS_LOGIN" in result.output
|
|
|
|
|
|
|
|
@mock.patch("aprsd.config.parse_config")
|
2022-07-07 11:02:43 -04:00
|
|
|
@mock.patch("aprsd.logging.log.setup_logging")
|
2021-12-12 16:35:26 -05:00
|
|
|
def test_no_plugin_arg(self, mock_logging, mock_parse_config):
|
|
|
|
"""Make sure we get an error if there is no login and config."""
|
|
|
|
|
|
|
|
runner = CliRunner()
|
|
|
|
mock_parse_config.return_value = self._build_config(login="something")
|
|
|
|
|
|
|
|
result = runner.invoke(
|
|
|
|
cli, ["dev", "test-plugin", "bogus command"],
|
|
|
|
catch_exceptions=False,
|
|
|
|
)
|
|
|
|
assert result.exit_code == 2
|
|
|
|
assert "Failed to provide -p option to test a plugin" in result.output
|