Files
aprsd/tests/fake.py
T

92 lines
1.8 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
FAKE_MESSAGE_TEXT = "fake MeSSage"
2021-12-07 11:25:14 -05:00
FAKE_FROM_CALLSIGN = "KFAKE"
2021-08-20 15:21:47 -04:00
FAKE_TO_CALLSIGN = "KMINE"
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 = {
2021-08-20 15:21:47 -04:00
"from": fromcall,
"addresse": tocall,
2022-12-13 15:25:46 -05:00
"to": tocall,
2021-08-20 15:21:47 -04:00
"format": message_format,
2022-12-13 15:25:46 -05:00
"raw": "",
2021-08-20 15:21:47 -04:00
}
if message:
packet_dict["message_text"] = message
2021-08-20 15:21:47 -04:00
if msg_number:
packet_dict["msgNo"] = str(msg_number)
2021-08-20 15:21:47 -04:00
2024-03-20 09:34:31 -04:00
if response:
packet_dict["response"] = response
return core.factory(packet_dict)
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):
version = "1.0"
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):
return "process"
class FakeThread(threads.APRSDThread):
def __init__(self):
super().__init__("FakeThread")
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):
version = "1.0"
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):
return "process"
def create_threads(self):
return FakeThread()
class FakeRegexCommandPlugin(plugin.APRSDRegexCommandPluginBase):
version = "1.0"
command_regex = "^[fF]"
command_name = "fake"
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