2022-12-13 15:25:46 -05:00
|
|
|
import typing as t
|
|
|
|
import unittest
|
|
|
|
from unittest import mock
|
|
|
|
|
|
|
|
from click.testing import CliRunner
|
|
|
|
import flask
|
|
|
|
import flask_socketio
|
2022-12-27 14:30:03 -05:00
|
|
|
from oslo_config import cfg
|
2022-12-13 15:25:46 -05:00
|
|
|
|
2022-12-27 14:30:03 -05:00
|
|
|
from aprsd import conf # noqa: F401
|
2022-12-13 15:25:46 -05:00
|
|
|
from aprsd.cmds import webchat # noqa
|
2022-12-16 15:28:31 -05:00
|
|
|
from aprsd.packets import core
|
2022-12-13 15:25:46 -05:00
|
|
|
|
|
|
|
from .. import fake
|
|
|
|
|
|
|
|
|
2022-12-27 14:30:03 -05:00
|
|
|
CONF = cfg.CONF
|
2022-12-13 15:25:46 -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
|
2022-12-13 15:25:46 -05:00
|
|
|
if login:
|
2022-12-27 14:30:03 -05:00
|
|
|
CONF.aprs_network.login = login
|
2022-12-13 15:25:46 -05:00
|
|
|
if password:
|
2022-12-27 14:30:03 -05:00
|
|
|
CONF.aprs_network.password = password
|
2022-12-13 15:25:46 -05:00
|
|
|
|
2022-12-27 14:30:03 -05:00
|
|
|
CONF.admin.user = "admin"
|
|
|
|
CONF.admin.password = "password"
|
2022-12-13 15:25:46 -05:00
|
|
|
|
2023-07-16 16:28:15 -04:00
|
|
|
@mock.patch("aprsd.log.log.setup_logging")
|
2022-12-27 14:30:03 -05:00
|
|
|
def test_init_flask(self, mock_logging):
|
2022-12-13 15:25:46 -05:00
|
|
|
"""Make sure we get an error if there is no login and config."""
|
|
|
|
|
|
|
|
CliRunner()
|
2022-12-27 14:30:03 -05:00
|
|
|
self.config_and_init()
|
2022-12-13 15:25:46 -05:00
|
|
|
|
2023-07-19 11:27:34 -04:00
|
|
|
socketio = webchat.init_flask("DEBUG", False)
|
2022-12-13 15:25:46 -05:00
|
|
|
self.assertIsInstance(socketio, flask_socketio.SocketIO)
|
2023-07-19 11:27:34 -04:00
|
|
|
self.assertIsInstance(webchat.flask_app, flask.Flask)
|
2022-12-13 15:25:46 -05:00
|
|
|
|
2022-12-16 15:28:31 -05:00
|
|
|
@mock.patch("aprsd.packets.tracker.PacketTrack.remove")
|
2022-12-27 14:30:03 -05:00
|
|
|
@mock.patch("aprsd.cmds.webchat.socketio")
|
2022-12-13 15:25:46 -05:00
|
|
|
def test_process_ack_packet(
|
2022-12-27 14:30:03 -05:00
|
|
|
self,
|
|
|
|
mock_remove, mock_socketio,
|
2022-12-13 15:25:46 -05:00
|
|
|
):
|
2022-12-27 14:30:03 -05:00
|
|
|
self.config_and_init()
|
|
|
|
mock_socketio.emit = mock.MagicMock()
|
2022-12-13 15:25:46 -05:00
|
|
|
packet = fake.fake_packet(
|
|
|
|
message="blah",
|
|
|
|
msg_number=1,
|
2022-12-16 15:28:31 -05:00
|
|
|
message_format=core.PACKET_TYPE_ACK,
|
2022-12-13 15:25:46 -05:00
|
|
|
)
|
2024-02-27 14:21:04 -05:00
|
|
|
mock_queue = mock.MagicMock()
|
2022-12-13 15:25:46 -05:00
|
|
|
socketio = mock.MagicMock()
|
2024-02-27 14:21:04 -05:00
|
|
|
wcp = webchat.WebChatProcessPacketThread(mock_queue, socketio)
|
2022-12-13 15:25:46 -05:00
|
|
|
|
|
|
|
wcp.process_ack_packet(packet)
|
|
|
|
mock_remove.called_once()
|
2022-12-27 14:30:03 -05:00
|
|
|
mock_socketio.called_once()
|
2022-12-13 15:25:46 -05:00
|
|
|
|
2024-02-27 14:21:04 -05:00
|
|
|
@mock.patch("aprsd.threads.tx.send")
|
2022-12-18 08:52:58 -05:00
|
|
|
@mock.patch("aprsd.packets.PacketList.rx")
|
2022-12-27 14:30:03 -05:00
|
|
|
@mock.patch("aprsd.cmds.webchat.socketio")
|
2022-12-14 22:03:21 -05:00
|
|
|
def test_process_our_message_packet(
|
2022-12-27 14:30:03 -05:00
|
|
|
self,
|
2024-02-27 14:21:04 -05:00
|
|
|
mock_tx_send,
|
2022-12-13 15:25:46 -05:00
|
|
|
mock_packet_add,
|
2022-12-27 14:30:03 -05:00
|
|
|
mock_socketio,
|
2022-12-13 15:25:46 -05:00
|
|
|
):
|
2022-12-27 14:30:03 -05:00
|
|
|
self.config_and_init()
|
|
|
|
mock_socketio.emit = mock.MagicMock()
|
2022-12-13 15:25:46 -05:00
|
|
|
packet = fake.fake_packet(
|
|
|
|
message="blah",
|
|
|
|
msg_number=1,
|
2022-12-16 15:28:31 -05:00
|
|
|
message_format=core.PACKET_TYPE_MESSAGE,
|
2022-12-13 15:25:46 -05:00
|
|
|
)
|
2024-02-27 14:21:04 -05:00
|
|
|
mock_queue = mock.MagicMock()
|
2022-12-13 15:25:46 -05:00
|
|
|
socketio = mock.MagicMock()
|
2024-02-27 14:21:04 -05:00
|
|
|
wcp = webchat.WebChatProcessPacketThread(mock_queue, socketio)
|
2022-12-13 15:25:46 -05:00
|
|
|
|
2022-12-14 22:03:21 -05:00
|
|
|
wcp.process_our_message_packet(packet)
|
2022-12-13 15:25:46 -05:00
|
|
|
mock_packet_add.called_once()
|
2022-12-27 14:30:03 -05:00
|
|
|
mock_socketio.called_once()
|