1
0
mirror of https://github.com/craigerl/aprsd.git synced 2024-11-17 22:01:49 -05:00

Added unit test for QueryPlugin

This patch adds a simple test for the QueryPlugin
This commit is contained in:
Hemna 2021-01-11 12:09:29 -05:00
parent 1ce2a56140
commit 68e6f5b986

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()