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
|
|
|
|
|
|
|
|
from aprsd import conf # noqa: F401
|
2021-12-07 11:25:14 -05:00
|
|
|
from aprsd.plugins import ping as ping_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 TestPingPlugin(test_plugin.TestPlugin):
|
|
|
|
@mock.patch("time.localtime")
|
|
|
|
def test_ping(self, mock_time):
|
|
|
|
fake_time = mock.MagicMock()
|
|
|
|
h = fake_time.tm_hour = 16
|
|
|
|
m = fake_time.tm_min = 12
|
|
|
|
s = fake_time.tm_sec = 55
|
|
|
|
mock_time.return_value = fake_time
|
|
|
|
|
2022-12-27 14:30:03 -05:00
|
|
|
CONF.callsign = fake.FAKE_TO_CALLSIGN
|
|
|
|
ping = ping_plugin.PingPlugin()
|
2021-12-07 11:25:14 -05:00
|
|
|
|
|
|
|
packet = fake.fake_packet(
|
|
|
|
message="location",
|
|
|
|
msg_number=1,
|
|
|
|
)
|
|
|
|
|
|
|
|
result = ping.filter(packet)
|
|
|
|
self.assertEqual(None, result)
|
|
|
|
|
|
|
|
def ping_str(h, m, s):
|
|
|
|
return (
|
|
|
|
"Pong! "
|
|
|
|
+ str(h).zfill(2)
|
|
|
|
+ ":"
|
|
|
|
+ str(m).zfill(2)
|
|
|
|
+ ":"
|
|
|
|
+ str(s).zfill(2)
|
|
|
|
)
|
|
|
|
|
|
|
|
packet = fake.fake_packet(
|
|
|
|
message="Ping",
|
|
|
|
msg_number=1,
|
|
|
|
)
|
|
|
|
actual = ping.filter(packet)
|
|
|
|
expected = ping_str(h, m, s)
|
|
|
|
self.assertEqual(expected, actual)
|
|
|
|
|
|
|
|
packet = fake.fake_packet(
|
|
|
|
message="ping",
|
|
|
|
msg_number=1,
|
|
|
|
)
|
|
|
|
actual = ping.filter(packet)
|
|
|
|
self.assertEqual(expected, actual)
|