1
0
mirror of https://github.com/craigerl/aprsd.git synced 2026-06-04 23:24:55 -04:00
Files
aprsd/tests/cmds/test_send_message.py
T

65 lines
1.8 KiB
Python
Raw Normal View History

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
from aprsd.cmds import send_message # noqa
2023-07-08 17:30:22 -04:00
from aprsd.main import cli
2021-12-12 16:13:08 -05:00
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
2026-01-05 16:51:54 -05:00
F = t.TypeVar('F', bound=t.Callable[..., t.Any])
2021-12-12 16:13:08 -05:00
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:
2026-01-18 21:21:09 -05:00
CONF.callsign = 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
2024-12-09 16:53:51 -05:00
# CONF.aprsd_admin_extension.user = "admin"
# CONF.aprsd_admin_extension.password = "password"
2021-12-12 16:13:08 -05:00
2026-01-05 16:51:54 -05:00
@mock.patch('aprsd.log.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(
2026-01-05 16:51:54 -05:00
login='something',
password='another',
2021-12-12 16:13:08 -05:00
)
2022-12-27 14:30:03 -05:00
runner = CliRunner()
2021-12-12 16:13:08 -05:00
result = runner.invoke(
2024-12-20 22:00:54 -05:00
cli,
2026-01-05 16:51:54 -05:00
['send-message'],
2021-12-12 16:13:08 -05:00
catch_exceptions=False,
)
assert result.exit_code == 2
assert "Error: Missing argument 'TOCALLSIGN'" in result.output
2026-01-05 16:51:54 -05:00
@mock.patch('aprsd.log.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(
2026-01-05 16:51:54 -05:00
login='something',
password='another',
2021-12-12 16:13:08 -05:00
)
2022-12-27 14:30:03 -05:00
runner = CliRunner()
2021-12-12 16:13:08 -05:00
result = runner.invoke(
2024-12-20 22:00:54 -05:00
cli,
2026-01-05 16:51:54 -05:00
['send-message', 'WB4BOR'],
2021-12-12 16:13:08 -05:00
catch_exceptions=False,
)
assert result.exit_code == 2
assert "Error: Missing argument 'COMMAND...'" in result.output