mirror of
https://github.com/craigerl/aprsd.git
synced 2026-06-11 18:38:48 -04:00
Removed references to old custom config
Also updated unittests to pass.
This commit is contained in:
+36
-45
@@ -1,7 +1,9 @@
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
from aprsd import config as aprsd_config
|
||||
from oslo_config import cfg
|
||||
|
||||
from aprsd import conf # noqa: F401
|
||||
from aprsd import packets
|
||||
from aprsd import plugin as aprsd_plugin
|
||||
from aprsd import plugins, stats
|
||||
@@ -10,6 +12,9 @@ from aprsd.packets import core
|
||||
from . import fake
|
||||
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
|
||||
class TestPluginManager(unittest.TestCase):
|
||||
|
||||
def setUp(self) -> None:
|
||||
@@ -21,34 +26,26 @@ class TestPluginManager(unittest.TestCase):
|
||||
aprsd_plugin.PluginManager._instance = None
|
||||
|
||||
def config_and_init(self):
|
||||
self.config = aprsd_config.Config(aprsd_config.DEFAULT_CONFIG_DICT)
|
||||
self.config["ham"]["callsign"] = self.fromcall
|
||||
self.config["aprs"]["login"] = fake.FAKE_TO_CALLSIGN
|
||||
self.config["services"]["aprs.fi"]["apiKey"] = "something"
|
||||
self.config["aprsd"]["enabled_plugins"] = [
|
||||
"aprsd.plugins.ping.PingPlugin",
|
||||
]
|
||||
print(self.config)
|
||||
|
||||
def test_init_no_config(self):
|
||||
pm = aprsd_plugin.PluginManager()
|
||||
self.assertEqual(None, pm.config)
|
||||
|
||||
def test_init_with_config(self):
|
||||
pm = aprsd_plugin.PluginManager(self.config)
|
||||
self.assertEqual(self.config, pm.config)
|
||||
CONF.callsign = self.fromcall
|
||||
CONF.aprs_network.login = fake.FAKE_TO_CALLSIGN
|
||||
CONF.aprs_fi.apiKey = "something"
|
||||
CONF.enabled_plugins = "aprsd.plugins.ping.PingPlugin"
|
||||
CONF.enable_save = False
|
||||
|
||||
def test_get_plugins_no_plugins(self):
|
||||
pm = aprsd_plugin.PluginManager(self.config)
|
||||
CONF.enabled_plugins = []
|
||||
pm = aprsd_plugin.PluginManager()
|
||||
plugin_list = pm.get_plugins()
|
||||
self.assertEqual([], plugin_list)
|
||||
|
||||
def test_get_plugins_with_plugins(self):
|
||||
pm = aprsd_plugin.PluginManager(self.config)
|
||||
CONF.enabled_plugins = ["aprsd.plugins.ping.PingPlugin"]
|
||||
pm = aprsd_plugin.PluginManager()
|
||||
plugin_list = pm.get_plugins()
|
||||
self.assertEqual([], plugin_list)
|
||||
pm.setup_plugins()
|
||||
plugin_list = pm.get_plugins()
|
||||
print(plugin_list)
|
||||
self.assertIsInstance(plugin_list, list)
|
||||
self.assertIsInstance(
|
||||
plugin_list[0],
|
||||
@@ -59,7 +56,7 @@ class TestPluginManager(unittest.TestCase):
|
||||
)
|
||||
|
||||
def test_get_watchlist_plugins(self):
|
||||
pm = aprsd_plugin.PluginManager(self.config)
|
||||
pm = aprsd_plugin.PluginManager()
|
||||
plugin_list = pm.get_plugins()
|
||||
self.assertEqual([], plugin_list)
|
||||
pm.setup_plugins()
|
||||
@@ -68,7 +65,8 @@ class TestPluginManager(unittest.TestCase):
|
||||
self.assertEqual(0, len(plugin_list))
|
||||
|
||||
def test_get_message_plugins(self):
|
||||
pm = aprsd_plugin.PluginManager(self.config)
|
||||
CONF.enabled_plugins = ["aprsd.plugins.ping.PingPlugin"]
|
||||
pm = aprsd_plugin.PluginManager()
|
||||
plugin_list = pm.get_plugins()
|
||||
self.assertEqual([], plugin_list)
|
||||
pm.setup_plugins()
|
||||
@@ -98,27 +96,19 @@ class TestPlugin(unittest.TestCase):
|
||||
packets.PacketTrack._instance = None
|
||||
self.config = None
|
||||
|
||||
def config_and_init(self, config=None):
|
||||
if not config:
|
||||
self.config = aprsd_config.Config(aprsd_config.DEFAULT_CONFIG_DICT)
|
||||
self.config["ham"]["callsign"] = self.fromcall
|
||||
self.config["aprs"]["login"] = fake.FAKE_TO_CALLSIGN
|
||||
self.config["services"]["aprs.fi"]["apiKey"] = "something"
|
||||
else:
|
||||
self.config = config
|
||||
|
||||
# Inintialize the stats object with the config
|
||||
stats.APRSDStats(self.config)
|
||||
packets.WatchList(config=self.config)
|
||||
packets.SeenList(config=self.config)
|
||||
packets.PacketTrack(config=self.config)
|
||||
def config_and_init(self):
|
||||
CONF.callsign = self.fromcall
|
||||
CONF.aprs_network.login = fake.FAKE_TO_CALLSIGN
|
||||
CONF.aprs_fi.apiKey = "something"
|
||||
CONF.enabled_plugins = "aprsd.plugins.ping.PingPlugin"
|
||||
CONF.enable_save = False
|
||||
|
||||
|
||||
class TestPluginBase(TestPlugin):
|
||||
|
||||
@mock.patch.object(fake.FakeBaseNoThreadsPlugin, "process")
|
||||
def test_base_plugin_no_threads(self, mock_process):
|
||||
p = fake.FakeBaseNoThreadsPlugin(self.config)
|
||||
p = fake.FakeBaseNoThreadsPlugin()
|
||||
|
||||
expected = []
|
||||
actual = p.create_threads()
|
||||
@@ -139,19 +129,20 @@ class TestPluginBase(TestPlugin):
|
||||
|
||||
@mock.patch.object(fake.FakeBaseThreadsPlugin, "create_threads")
|
||||
def test_base_plugin_threads_created(self, mock_create):
|
||||
p = fake.FakeBaseThreadsPlugin(self.config)
|
||||
p = fake.FakeBaseThreadsPlugin()
|
||||
mock_create.assert_called_once()
|
||||
p.stop_threads()
|
||||
|
||||
def test_base_plugin_threads(self):
|
||||
p = fake.FakeBaseThreadsPlugin(self.config)
|
||||
p = fake.FakeBaseThreadsPlugin()
|
||||
actual = p.create_threads()
|
||||
self.assertTrue(isinstance(actual, fake.FakeThread))
|
||||
p.stop_threads()
|
||||
|
||||
@mock.patch.object(fake.FakeRegexCommandPlugin, "process")
|
||||
def test_regex_base_not_called(self, mock_process):
|
||||
p = fake.FakeRegexCommandPlugin(self.config)
|
||||
CONF.callsign = fake.FAKE_TO_CALLSIGN
|
||||
p = fake.FakeRegexCommandPlugin()
|
||||
packet = fake.fake_packet(message="a")
|
||||
expected = None
|
||||
actual = p.filter(packet)
|
||||
@@ -165,32 +156,32 @@ class TestPluginBase(TestPlugin):
|
||||
mock_process.assert_not_called()
|
||||
|
||||
packet = fake.fake_packet(
|
||||
message="F",
|
||||
message_format=core.PACKET_TYPE_MICE,
|
||||
)
|
||||
expected = None
|
||||
expected = packets.NULL_MESSAGE
|
||||
actual = p.filter(packet)
|
||||
self.assertEqual(expected, actual)
|
||||
mock_process.assert_not_called()
|
||||
|
||||
packet = fake.fake_packet(
|
||||
message="f",
|
||||
message_format=core.PACKET_TYPE_ACK,
|
||||
)
|
||||
expected = None
|
||||
expected = packets.NULL_MESSAGE
|
||||
actual = p.filter(packet)
|
||||
self.assertEqual(expected, actual)
|
||||
mock_process.assert_not_called()
|
||||
|
||||
@mock.patch.object(fake.FakeRegexCommandPlugin, "process")
|
||||
def test_regex_base_assert_called(self, mock_process):
|
||||
p = fake.FakeRegexCommandPlugin(self.config)
|
||||
CONF.callsign = fake.FAKE_TO_CALLSIGN
|
||||
p = fake.FakeRegexCommandPlugin()
|
||||
packet = fake.fake_packet(message="f")
|
||||
p.filter(packet)
|
||||
mock_process.assert_called_once()
|
||||
|
||||
def test_regex_base_process_called(self):
|
||||
p = fake.FakeRegexCommandPlugin(self.config)
|
||||
CONF.callsign = fake.FAKE_TO_CALLSIGN
|
||||
p = fake.FakeRegexCommandPlugin()
|
||||
|
||||
packet = fake.fake_packet(message="f")
|
||||
expected = fake.FAKE_MESSAGE_TEXT
|
||||
|
||||
Reference in New Issue
Block a user