1
0
mirror of https://github.com/craigerl/aprsd.git synced 2026-06-12 10:58:54 -04:00
Files
aprsd/tests/plugins/test_fortune.py
T

35 lines
1.1 KiB
Python
Raw Normal View History

2021-12-07 11:25:14 -05:00
from unittest import mock
2022-12-27 14:30:03 -05:00
from oslo_config import cfg
from aprsd import conf # noqa: F401
2021-12-07 11:25:14 -05:00
from aprsd.plugins import fortune as fortune_plugin
from .. import fake, test_plugin
2022-12-27 14:30:03 -05:00
CONF = cfg.CONF
2021-12-07 11:25:14 -05:00
class TestFortunePlugin(test_plugin.TestPlugin):
2026-01-05 16:51:54 -05:00
@mock.patch('shutil.which')
2021-12-07 11:25:14 -05:00
def test_fortune_fail(self, mock_which):
mock_which.return_value = None
2022-12-27 14:30:03 -05:00
fortune = fortune_plugin.FortunePlugin()
2021-12-07 11:25:14 -05:00
expected = "FortunePlugin isn't enabled"
2026-01-05 16:51:54 -05:00
packet = fake.fake_packet(message='fortune')
2021-12-07 11:25:14 -05:00
actual = fortune.filter(packet)
self.assertEqual(expected, actual)
2026-01-05 16:51:54 -05:00
@mock.patch('subprocess.check_output')
@mock.patch('shutil.which')
2021-12-07 11:25:14 -05:00
def test_fortune_success(self, mock_which, mock_output):
2026-01-05 16:51:54 -05:00
mock_which.return_value = '/usr/bin/games/fortune'
mock_output.return_value = 'Funny fortune'
2022-12-27 14:30:03 -05:00
CONF.callsign = fake.FAKE_TO_CALLSIGN
fortune = fortune_plugin.FortunePlugin()
2021-12-07 11:25:14 -05:00
2026-01-05 16:51:54 -05:00
expected = 'Funny fortune'
packet = fake.fake_packet(message='fortune')
2021-12-07 11:25:14 -05:00
actual = fortune.filter(packet)
self.assertEqual(expected, actual)