1
0
mirror of https://github.com/craigerl/aprsd.git synced 2026-06-11 10:28:45 -04:00
Files
aprsd/tests/fake.py
T

110 lines
2.3 KiB
Python
Raw Normal View History

2024-03-20 09:34:31 -04:00
from aprsd import plugin, threads
2022-12-16 15:28:31 -05:00
from aprsd.packets import core
2021-08-20 15:21:47 -04:00
2026-01-05 16:51:54 -05:00
FAKE_MESSAGE_TEXT = 'fake MeSSage'
FAKE_FROM_CALLSIGN = 'KFAKE'
FAKE_TO_CALLSIGN = 'KMINE'
2021-08-20 15:21:47 -04:00
def fake_packet(
fromcall=FAKE_FROM_CALLSIGN,
tocall=FAKE_TO_CALLSIGN,
message=None,
msg_number=None,
2022-12-16 15:28:31 -05:00
message_format=core.PACKET_TYPE_MESSAGE,
2024-03-20 09:34:31 -04:00
response=None,
2021-08-20 15:21:47 -04:00
):
packet_dict = {
2026-01-05 16:51:54 -05:00
'from': fromcall,
'addresse': tocall,
'to': tocall,
'format': message_format,
'raw': '',
2021-08-20 15:21:47 -04:00
}
if message:
2026-01-05 16:51:54 -05:00
packet_dict['message_text'] = message
2021-08-20 15:21:47 -04:00
if msg_number:
2026-01-05 16:51:54 -05:00
packet_dict['msgNo'] = str(msg_number)
2021-08-20 15:21:47 -04:00
2024-03-20 09:34:31 -04:00
if response:
2026-01-05 16:51:54 -05:00
packet_dict['response'] = response
2024-03-20 09:34:31 -04:00
2026-01-06 18:57:54 -05:00
packet = core.factory(packet_dict)
# Call prepare to build the raw data
packet.prepare()
return packet
def fake_gps_packet():
"""Create a properly prepared GPSPacket for testing."""
packet = core.GPSPacket(
from_call=FAKE_FROM_CALLSIGN,
to_call=FAKE_TO_CALLSIGN,
latitude=37.7749,
longitude=-122.4194,
symbol='>',
comment='Test GPS comment',
)
# Call prepare to build the raw data
packet.prepare()
return packet
2024-03-20 09:34:31 -04:00
def fake_ack_packet():
return fake_packet(
msg_number=12,
response=core.PACKET_TYPE_ACK,
)
2021-08-20 15:21:47 -04:00
class FakeBaseNoThreadsPlugin(plugin.APRSDPluginBase):
2026-01-05 16:51:54 -05:00
version = '1.0'
2021-08-20 15:21:47 -04:00
2021-09-08 14:18:49 -04:00
def setup(self):
self.enabled = True
2021-08-20 15:21:47 -04:00
def filter(self, packet):
return None
def process(self, packet):
2026-01-05 16:51:54 -05:00
return 'process'
2021-08-20 15:21:47 -04:00
class FakeThread(threads.APRSDThread):
def __init__(self):
2026-01-05 16:51:54 -05:00
super().__init__('FakeThread')
2021-08-20 15:21:47 -04:00
def loop(self):
2021-12-07 11:25:14 -05:00
return False
2021-08-20 15:21:47 -04:00
class FakeBaseThreadsPlugin(plugin.APRSDPluginBase):
2026-01-05 16:51:54 -05:00
version = '1.0'
2021-08-20 15:21:47 -04:00
2021-09-08 14:18:49 -04:00
def setup(self):
self.enabled = True
2021-08-20 15:21:47 -04:00
def filter(self, packet):
return None
def process(self, packet):
2026-01-05 16:51:54 -05:00
return 'process'
2021-08-20 15:21:47 -04:00
def create_threads(self):
return FakeThread()
class FakeRegexCommandPlugin(plugin.APRSDRegexCommandPluginBase):
2026-01-05 16:51:54 -05:00
version = '1.0'
command_regex = '^[fF]'
command_name = 'fake'
2021-08-20 15:21:47 -04:00
def process(self, packet):
return FAKE_MESSAGE_TEXT
2021-12-07 11:25:14 -05:00
class FakeWatchListPlugin(plugin.APRSDWatchListPluginBase):
def process(self, packet):
return FAKE_MESSAGE_TEXT