mirror of
https://github.com/craigerl/aprsd.git
synced 2025-04-09 21:18:37 -04:00
Removed watchlist plugins
All plugins can be loaded with the enabled_plugins Also added unit tests for the PluginManager
This commit is contained in:
parent
2ca36362ec
commit
f464ff0785
@ -15,7 +15,6 @@ DEFAULT_CONFIG_DIR = f"{home}/.config/aprsd/"
|
||||
DEFAULT_SAVE_FILE = f"{home}/.config/aprsd/aprsd.p"
|
||||
DEFAULT_CONFIG_FILE = f"{home}/.config/aprsd/aprsd.yml"
|
||||
|
||||
|
||||
LOG_LEVELS = {
|
||||
"CRITICAL": logging.CRITICAL,
|
||||
"ERROR": logging.ERROR,
|
||||
@ -42,7 +41,6 @@ CORE_MESSAGE_PLUGINS = [
|
||||
"aprsd.plugins.location.LocationPlugin",
|
||||
"aprsd.plugins.ping.PingPlugin",
|
||||
"aprsd.plugins.query.QueryPlugin",
|
||||
"aprsd.plugins.stock.StockPlugin",
|
||||
"aprsd.plugins.time.TimePlugin",
|
||||
"aprsd.plugins.weather.USWeatherPlugin",
|
||||
"aprsd.plugins.version.VersionPlugin",
|
||||
@ -52,6 +50,12 @@ CORE_NOTIFY_PLUGINS = [
|
||||
"aprsd.plugins.notify.NotifySeenPlugin",
|
||||
]
|
||||
|
||||
ALL_PLUGINS = []
|
||||
for i in CORE_MESSAGE_PLUGINS:
|
||||
ALL_PLUGINS.append(i)
|
||||
for i in CORE_NOTIFY_PLUGINS:
|
||||
ALL_PLUGINS.append(i)
|
||||
|
||||
# an example of what should be in the ~/.aprsd/config.yml
|
||||
DEFAULT_CONFIG_DICT = {
|
||||
"ham": {"callsign": "NOCALL"},
|
||||
@ -85,7 +89,7 @@ DEFAULT_CONFIG_DICT = {
|
||||
"save_location": DEFAULT_CONFIG_DIR,
|
||||
"rich_logging": True,
|
||||
"trace": False,
|
||||
"enabled_plugins": CORE_MESSAGE_PLUGINS,
|
||||
"enabled_plugins": ALL_PLUGINS,
|
||||
"units": "imperial",
|
||||
"watch_list": {
|
||||
"enabled": False,
|
||||
@ -97,7 +101,6 @@ DEFAULT_CONFIG_DICT = {
|
||||
# for a particular callsign
|
||||
"packet_keep_count": 10,
|
||||
"callsigns": [],
|
||||
"enabled_plugins": CORE_NOTIFY_PLUGINS,
|
||||
},
|
||||
"web": {
|
||||
"enabled": True,
|
||||
|
@ -2,12 +2,88 @@ import unittest
|
||||
from unittest import mock
|
||||
|
||||
from aprsd import config as aprsd_config
|
||||
from aprsd import packets, stats
|
||||
from aprsd import packets
|
||||
from aprsd import plugin as aprsd_plugin
|
||||
from aprsd import plugins, stats
|
||||
from aprsd.packets import core
|
||||
|
||||
from . import fake
|
||||
|
||||
|
||||
class TestPluginManager(unittest.TestCase):
|
||||
|
||||
def setUp(self) -> None:
|
||||
self.fromcall = fake.FAKE_FROM_CALLSIGN
|
||||
self.config_and_init()
|
||||
|
||||
def tearDown(self) -> None:
|
||||
self.config = None
|
||||
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)
|
||||
|
||||
def test_get_plugins_no_plugins(self):
|
||||
pm = aprsd_plugin.PluginManager(self.config)
|
||||
plugin_list = pm.get_plugins()
|
||||
self.assertEqual([], plugin_list)
|
||||
|
||||
def test_get_plugins_with_plugins(self):
|
||||
pm = aprsd_plugin.PluginManager(self.config)
|
||||
plugin_list = pm.get_plugins()
|
||||
self.assertEqual([], plugin_list)
|
||||
pm.setup_plugins()
|
||||
plugin_list = pm.get_plugins()
|
||||
self.assertIsInstance(plugin_list, list)
|
||||
self.assertIsInstance(
|
||||
plugin_list[0],
|
||||
(
|
||||
aprsd_plugin.HelpPlugin,
|
||||
plugins.ping.PingPlugin,
|
||||
),
|
||||
)
|
||||
|
||||
def test_get_watchlist_plugins(self):
|
||||
pm = aprsd_plugin.PluginManager(self.config)
|
||||
plugin_list = pm.get_plugins()
|
||||
self.assertEqual([], plugin_list)
|
||||
pm.setup_plugins()
|
||||
plugin_list = pm.get_watchlist_plugins()
|
||||
self.assertIsInstance(plugin_list, list)
|
||||
self.assertEqual(0, len(plugin_list))
|
||||
|
||||
def test_get_message_plugins(self):
|
||||
pm = aprsd_plugin.PluginManager(self.config)
|
||||
plugin_list = pm.get_plugins()
|
||||
self.assertEqual([], plugin_list)
|
||||
pm.setup_plugins()
|
||||
plugin_list = pm.get_message_plugins()
|
||||
self.assertIsInstance(plugin_list, list)
|
||||
self.assertEqual(2, len(plugin_list))
|
||||
self.assertIsInstance(
|
||||
plugin_list[0],
|
||||
(
|
||||
aprsd_plugin.HelpPlugin,
|
||||
plugins.ping.PingPlugin,
|
||||
),
|
||||
)
|
||||
|
||||
|
||||
class TestPlugin(unittest.TestCase):
|
||||
|
||||
def setUp(self) -> None:
|
||||
|
Loading…
Reference in New Issue
Block a user