2021-12-12 16:13:08 -05:00
|
|
|
import typing as t
|
|
|
|
import unittest
|
|
|
|
from unittest import mock
|
|
|
|
|
|
|
|
from click.testing import CliRunner
|
2022-12-27 14:30:03 -05:00
|
|
|
from oslo_config import cfg
|
2021-12-12 16:13:08 -05:00
|
|
|
|
2022-12-27 14:30:03 -05:00
|
|
|
from aprsd import conf # noqa : F401
|
2021-12-12 16:13:08 -05:00
|
|
|
from aprsd.aprsd import cli
|
|
|
|
from aprsd.cmds import send_message # noqa
|
|
|
|
|
2022-12-27 14:30:03 -05:00
|
|
|
from .. import fake
|
2021-12-12 16:13:08 -05:00
|
|
|
|
2022-12-27 14:30:03 -05:00
|
|
|
|
|
|
|
CONF = cfg.CONF
|
2021-12-12 16:13:08 -05:00
|
|
|
F = t.TypeVar("F", bound=t.Callable[..., t.Any])
|
|
|
|
|
|
|
|
|
|
|
|
class TestSendMessageCommand(unittest.TestCase):
|
|
|
|
|
2022-12-27 14:30:03 -05:00
|
|
|
def config_and_init(self, login=None, password=None):
|
|
|
|
CONF.callsign = fake.FAKE_TO_CALLSIGN
|
|
|
|
CONF.trace_enabled = False
|
|
|
|
CONF.watch_list.packet_keep_count = 1
|
2021-12-12 16:13:08 -05:00
|
|
|
if login:
|
2022-12-27 14:30:03 -05:00
|
|
|
CONF.aprs_network.login = login
|
2021-12-12 16:13:08 -05:00
|
|
|
if password:
|
2022-12-27 14:30:03 -05:00
|
|
|
CONF.aprs_network.password = password
|
2021-12-12 16:13:08 -05:00
|
|
|
|
2022-12-27 14:30:03 -05:00
|
|
|
CONF.admin.user = "admin"
|
|
|
|
CONF.admin.password = "password"
|
2021-12-12 16:13:08 -05:00
|
|
|
|
2022-07-07 11:02:43 -04:00
|
|
|
@mock.patch("aprsd.logging.log.setup_logging")
|
2022-12-27 14:30:03 -05:00
|
|
|
def test_no_tocallsign(self, mock_logging):
|
2021-12-12 16:13:08 -05:00
|
|
|
"""Make sure we get an error if there is no tocallsign."""
|
|
|
|
|
2022-12-27 14:30:03 -05:00
|
|
|
self.config_and_init(
|
2021-12-12 16:13:08 -05:00
|
|
|
login="something",
|
|
|
|
password="another",
|
|
|
|
)
|
2022-12-27 14:30:03 -05:00
|
|
|
runner = CliRunner()
|
2021-12-12 16:13:08 -05:00
|
|
|
|
|
|
|
result = runner.invoke(
|
|
|
|
cli, ["send-message"],
|
|
|
|
catch_exceptions=False,
|
|
|
|
)
|
|
|
|
assert result.exit_code == 2
|
|
|
|
assert "Error: Missing argument 'TOCALLSIGN'" in result.output
|
|
|
|
|
2022-07-07 11:02:43 -04:00
|
|
|
@mock.patch("aprsd.logging.log.setup_logging")
|
2022-12-27 14:30:03 -05:00
|
|
|
def test_no_command(self, mock_logging):
|
2021-12-12 16:13:08 -05:00
|
|
|
"""Make sure we get an error if there is no command."""
|
|
|
|
|
2022-12-27 14:30:03 -05:00
|
|
|
self.config_and_init(
|
2021-12-12 16:13:08 -05:00
|
|
|
login="something",
|
|
|
|
password="another",
|
|
|
|
)
|
2022-12-27 14:30:03 -05:00
|
|
|
runner = CliRunner()
|
2021-12-12 16:13:08 -05:00
|
|
|
|
|
|
|
result = runner.invoke(
|
|
|
|
cli, ["send-message", "WB4BOR"],
|
|
|
|
catch_exceptions=False,
|
|
|
|
)
|
|
|
|
assert result.exit_code == 2
|
|
|
|
assert "Error: Missing argument 'COMMAND...'" in result.output
|