2021-12-07 11:25:14 -05:00
|
|
|
from unittest import mock
|
|
|
|
|
2022-12-27 14:30:03 -05:00
|
|
|
from oslo_config import cfg
|
|
|
|
|
2022-12-16 15:28:31 -05:00
|
|
|
from aprsd import packets
|
|
|
|
from aprsd.packets import tracker
|
2021-12-07 11:25:14 -05:00
|
|
|
from aprsd.plugins import query as query_plugin
|
|
|
|
|
|
|
|
from .. import fake, test_plugin
|
|
|
|
|
|
|
|
|
2022-12-27 14:30:03 -05:00
|
|
|
CONF = cfg.CONF
|
|
|
|
|
|
|
|
|
2021-12-07 11:25:14 -05:00
|
|
|
class TestQueryPlugin(test_plugin.TestPlugin):
|
2022-12-16 15:28:31 -05:00
|
|
|
@mock.patch("aprsd.packets.tracker.PacketTrack.flush")
|
2021-12-07 11:25:14 -05:00
|
|
|
def test_query_flush(self, mock_flush):
|
|
|
|
packet = fake.fake_packet(message="!delete")
|
2022-12-27 14:30:03 -05:00
|
|
|
CONF.callsign = fake.FAKE_TO_CALLSIGN
|
|
|
|
CONF.save_enabled = True
|
|
|
|
CONF.query_plugin.callsign = fake.FAKE_FROM_CALLSIGN
|
|
|
|
query = query_plugin.QueryPlugin()
|
|
|
|
query.enabled = True
|
2021-12-07 11:25:14 -05:00
|
|
|
|
|
|
|
expected = "Deleted ALL pending msgs."
|
|
|
|
actual = query.filter(packet)
|
|
|
|
mock_flush.assert_called_once()
|
|
|
|
self.assertEqual(expected, actual)
|
|
|
|
|
2022-12-16 15:28:31 -05:00
|
|
|
@mock.patch("aprsd.packets.tracker.PacketTrack.restart_delayed")
|
2021-12-07 11:25:14 -05:00
|
|
|
def test_query_restart_delayed(self, mock_restart):
|
2022-12-27 14:30:03 -05:00
|
|
|
CONF.callsign = fake.FAKE_TO_CALLSIGN
|
|
|
|
CONF.save_enabled = True
|
|
|
|
CONF.query_plugin.callsign = fake.FAKE_FROM_CALLSIGN
|
2022-12-16 15:28:31 -05:00
|
|
|
track = tracker.PacketTrack()
|
2021-12-07 11:25:14 -05:00
|
|
|
track.data = {}
|
|
|
|
packet = fake.fake_packet(message="!4")
|
2022-12-27 14:30:03 -05:00
|
|
|
query = query_plugin.QueryPlugin()
|
2021-12-07 11:25:14 -05:00
|
|
|
|
|
|
|
expected = "No pending msgs to resend"
|
|
|
|
actual = query.filter(packet)
|
|
|
|
mock_restart.assert_not_called()
|
|
|
|
self.assertEqual(expected, actual)
|
|
|
|
mock_restart.reset_mock()
|
|
|
|
|
|
|
|
# add a message
|
2022-12-16 15:28:31 -05:00
|
|
|
pkt = packets.MessagePacket(
|
|
|
|
from_call=self.fromcall,
|
|
|
|
to_call="testing",
|
|
|
|
msgNo=self.ack,
|
|
|
|
)
|
|
|
|
track.add(pkt)
|
2021-12-07 11:25:14 -05:00
|
|
|
actual = query.filter(packet)
|
|
|
|
mock_restart.assert_called_once()
|