1
0
mirror of https://github.com/craigerl/aprsd.git synced 2025-07-31 12:52:24 -04:00

Merge branch 'craiger-stable' of https://github.com/craigerl/aprsd into craiger-stable

This commit is contained in:
Craig Lamparter 2021-01-11 09:13:51 -08:00
commit 839256c76d

View File

@ -2,9 +2,11 @@ import unittest
from unittest import mock from unittest import mock
import aprsd import aprsd
from aprsd import messaging
from aprsd.fuzzyclock import fuzzy from aprsd.fuzzyclock import fuzzy
from aprsd.plugins import fortune as fortune_plugin from aprsd.plugins import fortune as fortune_plugin
from aprsd.plugins import ping as ping_plugin from aprsd.plugins import ping as ping_plugin
from aprsd.plugins import query as query_plugin
from aprsd.plugins import time as time_plugin from aprsd.plugins import time as time_plugin
from aprsd.plugins import version as version_plugin from aprsd.plugins import version as version_plugin
@ -13,7 +15,7 @@ class TestPlugin(unittest.TestCase):
def setUp(self): def setUp(self):
self.fromcall = "KFART" self.fromcall = "KFART"
self.ack = 1 self.ack = 1
self.config = mock.MagicMock() self.config = {"ham": {"callsign": self.fromcall}}
@mock.patch("shutil.which") @mock.patch("shutil.which")
def test_fortune_fail(self, mock_which): def test_fortune_fail(self, mock_which):
@ -39,6 +41,35 @@ class TestPlugin(unittest.TestCase):
actual = fortune.run(self.fromcall, message, self.ack) actual = fortune.run(self.fromcall, message, self.ack)
self.assertEqual(expected, actual) self.assertEqual(expected, actual)
@mock.patch("aprsd.messaging.MsgTrack.flush")
def test_query_flush(self, mock_flush):
message = "?delete"
query = query_plugin.QueryPlugin(self.config)
expected = "Deleted ALL delayed msgs."
actual = query.run(self.fromcall, message, self.ack)
mock_flush.assert_called_once()
self.assertEqual(expected, actual)
@mock.patch("aprsd.messaging.MsgTrack.restart_delayed")
def test_query_restart_delayed(self, mock_restart):
track = messaging.MsgTrack()
track.track = {}
message = "?r4"
query = query_plugin.QueryPlugin(self.config)
expected = "No Delayed Msgs"
actual = query.run(self.fromcall, message, self.ack)
mock_restart.assert_not_called()
self.assertEqual(expected, actual)
mock_restart.reset_mock()
# add a message
msg = messaging.TextMessage(self.fromcall, "testing", self.ack)
track.add(msg)
actual = query.run(self.fromcall, message, self.ack)
mock_restart.assert_called_once()
@mock.patch("time.localtime") @mock.patch("time.localtime")
def test_time(self, mock_time): def test_time(self, mock_time):
fake_time = mock.MagicMock() fake_time = mock.MagicMock()