mirror of
https://github.com/craigerl/aprsd.git
synced 2026-01-19 20:15:33 -05:00
This adds a new option in the aprsd.conf [DEFAULT] section that denotes who is the callsign that officially owns this APRSD instance. This will be used for sending the instance info to the registry. It's useful when the callsign used by the instance is something useful on the APRS network, which isn't necessarily the same as the person that owns it.
85 lines
2.6 KiB
Python
85 lines
2.6 KiB
Python
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
|
|
|
|
CONF = cfg.CONF
|
|
|
|
|
|
class TestVersionPlugin(test_plugin.TestPlugin):
|
|
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',
|
|
}
|
|
}
|
|
|
|
CONF.callsign = fake.FAKE_TO_CALLSIGN
|
|
CONF.owner_callsign = None
|
|
expected = f'APRSD ver:{aprsd.__version__} uptime:00:00:00 owner:-'
|
|
version = version_plugin.VersionPlugin()
|
|
version.enabled = True
|
|
|
|
packet = fake.fake_packet(
|
|
message='No',
|
|
msg_number=1,
|
|
)
|
|
|
|
actual = version.filter(packet)
|
|
self.assertEqual(None, actual)
|
|
|
|
packet = fake.fake_packet(
|
|
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()
|
|
|
|
@mock.patch('aprsd.stats.collector.Collector')
|
|
def test_version_shows_owner_callsign_when_set(self, mock_collector_class):
|
|
mock_collector_instance = mock_collector_class.return_value
|
|
mock_collector_instance.collect.return_value = {
|
|
'APRSDStats': {'uptime': '01:23:45'},
|
|
}
|
|
|
|
CONF.callsign = fake.FAKE_TO_CALLSIGN
|
|
CONF.owner_callsign = 'K0WN3R'
|
|
version = version_plugin.VersionPlugin()
|
|
version.enabled = True
|
|
|
|
packet = fake.fake_packet(message='version', msg_number=1)
|
|
actual = version.filter(packet)
|
|
self.assertEqual(
|
|
actual,
|
|
f'APRSD ver:{aprsd.__version__} uptime:01:23:45 owner:K0WN3R',
|
|
)
|