1
0
mirror of https://github.com/craigerl/aprsd.git synced 2026-06-10 18:08:44 -04:00
Files
aprsd/tests/plugins/test_ping.py
T

57 lines
1.4 KiB
Python
Raw Normal View History

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):
2026-01-05 16:51:54 -05:00
@mock.patch('time.localtime')
2021-12-07 11:25:14 -05:00
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(
2026-01-05 16:51:54 -05:00
message='location',
2021-12-07 11:25:14 -05:00
msg_number=1,
)
result = ping.filter(packet)
self.assertEqual(None, result)
def ping_str(h, m, s):
return (
2026-01-05 16:51:54 -05:00
'Pong! '
2021-12-07 11:25:14 -05:00
+ str(h).zfill(2)
2026-01-05 16:51:54 -05:00
+ ':'
2021-12-07 11:25:14 -05:00
+ str(m).zfill(2)
2026-01-05 16:51:54 -05:00
+ ':'
2021-12-07 11:25:14 -05:00
+ str(s).zfill(2)
)
packet = fake.fake_packet(
2026-01-05 16:51:54 -05:00
message='Ping',
2021-12-07 11:25:14 -05:00
msg_number=1,
)
actual = ping.filter(packet)
expected = ping_str(h, m, s)
self.assertEqual(expected, actual)
packet = fake.fake_packet(
2026-01-05 16:51:54 -05:00
message='ping',
2021-12-07 11:25:14 -05:00
msg_number=1,
)
actual = ping.filter(packet)
self.assertEqual(expected, actual)