mirror of
https://github.com/craigerl/aprsd.git
synced 2026-06-10 18:08:44 -04:00
Reworked the entire client and drivers
This patch includes a completely reworked client structure. There is now only 1 client object, that loads the appropriate drivers. The drivers are fake, aprsis and tcpkiss. The TCPKISS client was written from scratch to avoid using asyncio. Asyncion is nothing but a pain in the ass.
This commit is contained in:
+38
-18
@@ -9,9 +9,11 @@ from aprsd import ( # noqa: F401
|
||||
plugins,
|
||||
)
|
||||
from aprsd import plugin as aprsd_plugin
|
||||
from aprsd.client.drivers.registry import DriverRegistry
|
||||
from aprsd.packets import core
|
||||
|
||||
from . import fake
|
||||
from .mock_client_driver import MockClientDriver
|
||||
|
||||
CONF = cfg.CONF
|
||||
|
||||
@@ -21,15 +23,24 @@ class TestPluginManager(unittest.TestCase):
|
||||
self.fromcall = fake.FAKE_FROM_CALLSIGN
|
||||
self.config_and_init()
|
||||
|
||||
self.mock_driver = MockClientDriver()
|
||||
# Mock the DriverRegistry to return our mock driver
|
||||
self.registry_patcher = mock.patch.object(
|
||||
DriverRegistry, 'get_driver', return_value=self.mock_driver
|
||||
)
|
||||
self.mock_registry = self.registry_patcher.start()
|
||||
|
||||
def tearDown(self) -> None:
|
||||
self.config = None
|
||||
aprsd_plugin.PluginManager._instance = None
|
||||
self.registry_patcher.stop()
|
||||
self.mock_registry.stop()
|
||||
|
||||
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.aprs_fi.apiKey = 'something'
|
||||
CONF.enabled_plugins = 'aprsd.plugins.ping.PingPlugin'
|
||||
CONF.enable_save = False
|
||||
|
||||
def test_get_plugins_no_plugins(self):
|
||||
@@ -39,7 +50,7 @@ class TestPluginManager(unittest.TestCase):
|
||||
self.assertEqual([], plugin_list)
|
||||
|
||||
def test_get_plugins_with_plugins(self):
|
||||
CONF.enabled_plugins = ["aprsd.plugins.ping.PingPlugin"]
|
||||
CONF.enabled_plugins = ['aprsd.plugins.ping.PingPlugin']
|
||||
pm = aprsd_plugin.PluginManager()
|
||||
plugin_list = pm.get_plugins()
|
||||
self.assertEqual([], plugin_list)
|
||||
@@ -64,7 +75,7 @@ class TestPluginManager(unittest.TestCase):
|
||||
self.assertEqual(0, len(plugin_list))
|
||||
|
||||
def test_get_message_plugins(self):
|
||||
CONF.enabled_plugins = ["aprsd.plugins.ping.PingPlugin"]
|
||||
CONF.enabled_plugins = ['aprsd.plugins.ping.PingPlugin']
|
||||
pm = aprsd_plugin.PluginManager()
|
||||
plugin_list = pm.get_plugins()
|
||||
self.assertEqual([], plugin_list)
|
||||
@@ -87,22 +98,31 @@ class TestPlugin(unittest.TestCase):
|
||||
self.ack = 1
|
||||
self.config_and_init()
|
||||
|
||||
self.mock_driver = MockClientDriver()
|
||||
# Mock the DriverRegistry to return our mock driver
|
||||
self.registry_patcher = mock.patch.object(
|
||||
DriverRegistry, 'get_driver', return_value=self.mock_driver
|
||||
)
|
||||
self.mock_registry = self.registry_patcher.start()
|
||||
|
||||
def tearDown(self) -> None:
|
||||
packets.WatchList._instance = None
|
||||
packets.SeenList._instance = None
|
||||
packets.PacketTrack._instance = None
|
||||
self.config = None
|
||||
self.registry_patcher.stop()
|
||||
self.mock_registry.stop()
|
||||
|
||||
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.aprs_fi.apiKey = 'something'
|
||||
CONF.enabled_plugins = 'aprsd.plugins.ping.PingPlugin'
|
||||
CONF.enable_save = False
|
||||
|
||||
|
||||
class TestPluginBase(TestPlugin):
|
||||
@mock.patch.object(fake.FakeBaseNoThreadsPlugin, "process")
|
||||
@mock.patch.object(fake.FakeBaseNoThreadsPlugin, 'process')
|
||||
def test_base_plugin_no_threads(self, mock_process):
|
||||
p = fake.FakeBaseNoThreadsPlugin()
|
||||
|
||||
@@ -110,7 +130,7 @@ class TestPluginBase(TestPlugin):
|
||||
actual = p.create_threads()
|
||||
self.assertEqual(expected, actual)
|
||||
|
||||
expected = "1.0"
|
||||
expected = '1.0'
|
||||
actual = p.version
|
||||
self.assertEqual(expected, actual)
|
||||
|
||||
@@ -123,7 +143,7 @@ class TestPluginBase(TestPlugin):
|
||||
self.assertEqual(expected, actual)
|
||||
mock_process.assert_not_called()
|
||||
|
||||
@mock.patch.object(fake.FakeBaseThreadsPlugin, "create_threads")
|
||||
@mock.patch.object(fake.FakeBaseThreadsPlugin, 'create_threads')
|
||||
def test_base_plugin_threads_created(self, mock_create):
|
||||
p = fake.FakeBaseThreadsPlugin()
|
||||
mock_create.assert_called_once()
|
||||
@@ -135,17 +155,17 @@ class TestPluginBase(TestPlugin):
|
||||
self.assertTrue(isinstance(actual, fake.FakeThread))
|
||||
p.stop_threads()
|
||||
|
||||
@mock.patch.object(fake.FakeRegexCommandPlugin, "process")
|
||||
@mock.patch.object(fake.FakeRegexCommandPlugin, 'process')
|
||||
def test_regex_base_not_called(self, mock_process):
|
||||
CONF.callsign = fake.FAKE_TO_CALLSIGN
|
||||
p = fake.FakeRegexCommandPlugin()
|
||||
packet = fake.fake_packet(message="a")
|
||||
packet = fake.fake_packet(message='a')
|
||||
expected = None
|
||||
actual = p.filter(packet)
|
||||
self.assertEqual(expected, actual)
|
||||
mock_process.assert_not_called()
|
||||
|
||||
packet = fake.fake_packet(tocall="notMe", message="f")
|
||||
packet = fake.fake_packet(tocall='notMe', message='f')
|
||||
expected = None
|
||||
actual = p.filter(packet)
|
||||
self.assertEqual(expected, actual)
|
||||
@@ -165,11 +185,11 @@ class TestPluginBase(TestPlugin):
|
||||
self.assertEqual(expected, actual)
|
||||
mock_process.assert_not_called()
|
||||
|
||||
@mock.patch.object(fake.FakeRegexCommandPlugin, "process")
|
||||
@mock.patch.object(fake.FakeRegexCommandPlugin, 'process')
|
||||
def test_regex_base_assert_called(self, mock_process):
|
||||
CONF.callsign = fake.FAKE_TO_CALLSIGN
|
||||
p = fake.FakeRegexCommandPlugin()
|
||||
packet = fake.fake_packet(message="f")
|
||||
packet = fake.fake_packet(message='f')
|
||||
p.filter(packet)
|
||||
mock_process.assert_called_once()
|
||||
|
||||
@@ -177,22 +197,22 @@ class TestPluginBase(TestPlugin):
|
||||
CONF.callsign = fake.FAKE_TO_CALLSIGN
|
||||
p = fake.FakeRegexCommandPlugin()
|
||||
|
||||
packet = fake.fake_packet(message="f")
|
||||
packet = fake.fake_packet(message='f')
|
||||
expected = fake.FAKE_MESSAGE_TEXT
|
||||
actual = p.filter(packet)
|
||||
self.assertEqual(expected, actual)
|
||||
|
||||
packet = fake.fake_packet(message="F")
|
||||
packet = fake.fake_packet(message='F')
|
||||
expected = fake.FAKE_MESSAGE_TEXT
|
||||
actual = p.filter(packet)
|
||||
self.assertEqual(expected, actual)
|
||||
|
||||
packet = fake.fake_packet(message="fake")
|
||||
packet = fake.fake_packet(message='fake')
|
||||
expected = fake.FAKE_MESSAGE_TEXT
|
||||
actual = p.filter(packet)
|
||||
self.assertEqual(expected, actual)
|
||||
|
||||
packet = fake.fake_packet(message="FAKE")
|
||||
packet = fake.fake_packet(message='FAKE')
|
||||
expected = fake.FAKE_MESSAGE_TEXT
|
||||
actual = p.filter(packet)
|
||||
self.assertEqual(expected, actual)
|
||||
|
||||
Reference in New Issue
Block a user