1
0
mirror of https://github.com/craigerl/aprsd.git synced 2026-06-01 21:54:42 -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:
2025-03-28 09:16:06 -04:00
parent 8f471c229c
commit 1c39546bb9
39 changed files with 2672 additions and 1493 deletions
+43 -36
View File
@@ -7,9 +7,11 @@ from aprsd import ( # noqa: F401
conf,
packets,
)
from aprsd.client.drivers.registry import DriverRegistry
from aprsd.plugins import notify as notify_plugin
from .. import fake, test_plugin
from ..mock_client_driver import MockClientDriver
CONF = cfg.CONF
DEFAULT_WATCHLIST_CALLSIGNS = fake.FAKE_FROM_CALLSIGN
@@ -17,9 +19,24 @@ DEFAULT_WATCHLIST_CALLSIGNS = fake.FAKE_FROM_CALLSIGN
class TestWatchListPlugin(test_plugin.TestPlugin):
def setUp(self):
super().setUp()
self.fromcall = fake.FAKE_FROM_CALLSIGN
self.ack = 1
# Mock APRSISDriver
self.aprsis_patcher = mock.patch('aprsd.client.drivers.aprsis.APRSISDriver')
self.mock_aprsis = self.aprsis_patcher.start()
self.mock_aprsis.is_enabled.return_value = False
self.mock_aprsis.is_configured.return_value = False
# Register the mock driver
DriverRegistry().register(MockClientDriver)
def tearDown(self):
super().tearDown()
if hasattr(self, 'aprsis_patcher'):
self.aprsis_patcher.stop()
def config_and_init(
self,
watchlist_enabled=True,
@@ -30,7 +47,9 @@ class TestWatchListPlugin(test_plugin.TestPlugin):
):
CONF.callsign = self.fromcall
CONF.aprs_network.login = self.fromcall
CONF.aprs_fi.apiKey = "something"
CONF.aprs_fi.apiKey = 'something'
# Add mock password
CONF.aprs_network.password = '12345'
# Set the watchlist specific config options
CONF.watch_list.enabled = watchlist_enabled
@@ -56,22 +75,20 @@ class TestAPRSDWatchListPluginBase(TestWatchListPlugin):
plugin = fake.FakeWatchListPlugin()
packet = fake.fake_packet(
message="version",
message='version',
msg_number=1,
)
actual = plugin.filter(packet)
expected = packets.NULL_MESSAGE
self.assertEqual(expected, actual)
@mock.patch("aprsd.client.factory.ClientFactory", autospec=True)
def test_watchlist_not_in_watchlist(self, mock_factory):
client.client_factory = mock_factory
def test_watchlist_not_in_watchlist(self):
self.config_and_init()
plugin = fake.FakeWatchListPlugin()
packet = fake.fake_packet(
fromcall="FAKE",
message="version",
fromcall='FAKE',
message='version',
msg_number=1,
)
actual = plugin.filter(packet)
@@ -85,87 +102,77 @@ class TestNotifySeenPlugin(TestWatchListPlugin):
plugin = notify_plugin.NotifySeenPlugin()
packet = fake.fake_packet(
message="version",
message='version',
msg_number=1,
)
actual = plugin.filter(packet)
expected = packets.NULL_MESSAGE
self.assertEqual(expected, actual)
@mock.patch("aprsd.client.factory.ClientFactory", autospec=True)
def test_callsign_not_in_watchlist(self, mock_factory):
client.client_factory = mock_factory
def test_callsign_not_in_watchlist(self):
self.config_and_init(watchlist_enabled=False)
plugin = notify_plugin.NotifySeenPlugin()
packet = fake.fake_packet(
message="version",
message='version',
msg_number=1,
)
actual = plugin.filter(packet)
expected = packets.NULL_MESSAGE
self.assertEqual(expected, actual)
@mock.patch("aprsd.client.factory.ClientFactory", autospec=True)
@mock.patch("aprsd.packets.WatchList.is_old")
def test_callsign_in_watchlist_not_old(self, mock_is_old, mock_factory):
client.client_factory = mock_factory
@mock.patch('aprsd.packets.WatchList.is_old')
def test_callsign_in_watchlist_not_old(self, mock_is_old):
mock_is_old.return_value = False
self.config_and_init(
watchlist_enabled=True,
watchlist_callsigns=["WB4BOR"],
watchlist_callsigns=['WB4BOR'],
)
plugin = notify_plugin.NotifySeenPlugin()
packet = fake.fake_packet(
fromcall="WB4BOR",
message="ping",
fromcall='WB4BOR',
message='ping',
msg_number=1,
)
actual = plugin.filter(packet)
expected = packets.NULL_MESSAGE
self.assertEqual(expected, actual)
@mock.patch("aprsd.client.factory.ClientFactory", autospec=True)
@mock.patch("aprsd.packets.WatchList.is_old")
def test_callsign_in_watchlist_old_same_alert_callsign(
self, mock_is_old, mock_factory
):
client.client_factory = mock_factory
@mock.patch('aprsd.packets.WatchList.is_old')
def test_callsign_in_watchlist_old_same_alert_callsign(self, mock_is_old):
mock_is_old.return_value = True
self.config_and_init(
watchlist_enabled=True,
watchlist_alert_callsign="WB4BOR",
watchlist_callsigns=["WB4BOR"],
watchlist_alert_callsign='WB4BOR',
watchlist_callsigns=['WB4BOR'],
)
plugin = notify_plugin.NotifySeenPlugin()
packet = fake.fake_packet(
fromcall="WB4BOR",
message="ping",
fromcall='WB4BOR',
message='ping',
msg_number=1,
)
actual = plugin.filter(packet)
expected = packets.NULL_MESSAGE
self.assertEqual(expected, actual)
@mock.patch("aprsd.client.factory.ClientFactory", autospec=True)
@mock.patch("aprsd.packets.WatchList.is_old")
def test_callsign_in_watchlist_old_send_alert(self, mock_is_old, mock_factory):
client.client_factory = mock_factory
@mock.patch('aprsd.packets.WatchList.is_old')
def test_callsign_in_watchlist_old_send_alert(self, mock_is_old):
mock_is_old.return_value = True
notify_callsign = fake.FAKE_TO_CALLSIGN
fromcall = "WB4BOR"
fromcall = 'WB4BOR'
self.config_and_init(
watchlist_enabled=True,
watchlist_alert_callsign=notify_callsign,
watchlist_callsigns=["WB4BOR"],
watchlist_callsigns=['WB4BOR'],
)
plugin = notify_plugin.NotifySeenPlugin()
packet = fake.fake_packet(
fromcall=fromcall,
message="ping",
message='ping',
msg_number=1,
)
packet_type = packet.__class__.__name__
+35 -6
View File
@@ -3,6 +3,7 @@ from unittest import mock
from oslo_config import cfg
import aprsd
from aprsd.client.drivers.fake import APRSDFakeDriver
from aprsd.plugins import version as version_plugin
from .. import fake, test_plugin
@@ -11,16 +12,41 @@ CONF = cfg.CONF
class TestVersionPlugin(test_plugin.TestPlugin):
@mock.patch("aprsd.stats.app.APRSDStats.uptime")
def test_version(self, mock_stats):
mock_stats.return_value = "00:00:00"
expected = f"APRSD ver:{aprsd.__version__} uptime:00:00:00"
def setUp(self):
# make sure the fake client driver is enabled
# Mock CONF for testing
super().setUp()
self.conf_patcher = mock.patch('aprsd.client.drivers.fake.CONF')
self.mock_conf = self.conf_patcher.start()
# Configure fake_client.enabled
self.mock_conf.fake_client.enabled = True
# Create an instance of the driver
self.driver = APRSDFakeDriver()
self.fromcall = fake.FAKE_FROM_CALLSIGN
def tearDown(self):
self.conf_patcher.stop()
super().tearDown()
@mock.patch('aprsd.stats.collector.Collector')
def test_version(self, mock_collector_class):
# Set up the mock collector instance
mock_collector_instance = mock_collector_class.return_value
mock_collector_instance.collect.return_value = {
'APRSDStats': {
'uptime': '00:00:00',
}
}
expected = f'APRSD ver:{aprsd.__version__} uptime:00:00:00'
CONF.callsign = fake.FAKE_TO_CALLSIGN
version = version_plugin.VersionPlugin()
version.enabled = True
packet = fake.fake_packet(
message="No",
message='No',
msg_number=1,
)
@@ -28,8 +54,11 @@ class TestVersionPlugin(test_plugin.TestPlugin):
self.assertEqual(None, actual)
packet = fake.fake_packet(
message="version",
message='version',
msg_number=1,
)
actual = version.filter(packet)
self.assertEqual(expected, actual)
# Verify the mock was called exactly once
mock_collector_instance.collect.assert_called_once()