|
6 | 6 | """ |
7 | 7 | Tests the Bot class itself. |
8 | 8 | """ |
9 | | -import json |
10 | 9 | import unittest |
11 | 10 |
|
12 | 11 | import intelmq.lib.test as test |
13 | 12 | from intelmq.tests.lib import test_parser_bot |
14 | | -from intelmq.lib.message import MessageFactory, Message |
15 | | -from intelmq.lib.bot import BotLibSettings |
16 | 13 |
|
17 | 14 |
|
18 | 15 | class TestDummyParserBot(test.BotTestCase, unittest.TestCase): |
@@ -81,65 +78,5 @@ def test_invalid_value_on_input_message(self): |
81 | 78 | self.assertEqual(self.pipe.state['test-bot-output'], []) |
82 | 79 |
|
83 | 80 |
|
84 | | -def send_message(self, *messages, path: str = "_default", auto_add=None, |
85 | | - path_permissive: bool = False): |
86 | | - self._sent_messages.extend(messages) |
87 | | - |
88 | | - |
89 | | -class TestBotAsLibrary(unittest.TestCase): |
90 | | - def assertMessageEqual(self, actual, expected): |
91 | | - """ |
92 | | - Compare two messages as dicts. |
93 | | - """ |
94 | | - if isinstance(actual, Message): |
95 | | - actual = actual.to_dict(with_type=True) |
96 | | - else: |
97 | | - actual = actual.copy() |
98 | | - |
99 | | - if isinstance(expected, Message): |
100 | | - expected = expected.to_dict(with_type=True) |
101 | | - else: |
102 | | - expected = expected.copy() |
103 | | - |
104 | | - if 'time.observation' in actual: |
105 | | - del actual['time.observation'] |
106 | | - if 'time.observation' in expected: |
107 | | - del expected['time.observation'] |
108 | | - if 'output' in actual: |
109 | | - actual['output'] = json.loads(actual['output']) |
110 | | - if 'output' in expected: |
111 | | - expected['output'] = json.loads(expected['output']) |
112 | | - |
113 | | - self.assertDictEqual(actual, expected) |
114 | | - |
115 | | - """def test_dummy_mocked(self): |
116 | | - bot = test_parser_bot.DummyParserBot('dummy-bot', settings={'global': {'logging_path': None, 'skip_pipeline': True, 'broker': 'pythonlist'}, 'dummy-bot': {}}) |
117 | | - bot._Bot__current_message = MessageFactory.from_dict(test_parser_bot.EXAMPLE_REPORT) |
118 | | - bot._Bot__connect_pipelines = lambda self: None |
119 | | - bot._sent_messages = [] |
120 | | - bot._dumped_messages = [] |
121 | | - bot.send_message = send_message.__get__(bot, test_parser_bot.DummyParserBot) |
122 | | - bot._dump_message = _dump_message.__get__(bot, test_parser_bot.DummyParserBot) |
123 | | - bot.process() |
124 | | - assert bot._sent_messages == [MessageFactory.from_dict(test_parser_bot.EXAMPLE_EVENT)] |
125 | | - assert bot._dumped_messages[0][1] == test_parser_bot.EXPECTED_DUMP[0] |
126 | | - assert bot._dumped_messages[1][1] == test_parser_bot.EXPECTED_DUMP[1]""" |
127 | | - |
128 | | - def test_dummy_pythonlist(self): |
129 | | - bot = test_parser_bot.DummyParserBot('dummy-bot', settings=BotLibSettings) |
130 | | - sent_messages = bot.process_message(test_parser_bot.EXAMPLE_REPORT.copy()) |
131 | | - self.assertMessageEqual(sent_messages['output'][0], test_parser_bot.EXAMPLE_EVENT) |
132 | | - self.assertMessageEqual(sent_messages['error'][0], MessageFactory.from_dict(test_parser_bot.EXPECTED_DUMP[0].copy(), default_type='Report')) |
133 | | - self.assertMessageEqual(sent_messages['error'][1], MessageFactory.from_dict(test_parser_bot.EXPECTED_DUMP[1].copy(), default_type='Report')) |
134 | | - |
135 | | - def test_domain_suffix(self): |
136 | | - from intelmq.bots.experts.domain_suffix.expert import DomainSuffixExpertBot |
137 | | - domain_suffix = DomainSuffixExpertBot('domain-suffix', |
138 | | - settings=BotLibSettings | {'field': 'fqdn', |
139 | | - 'suffix_file': '/usr/share/publicsuffix/public_suffix_list.dat'}) |
140 | | - queues = domain_suffix.process_message({'source.fqdn': 'www.example.com'}) |
141 | | - assert queues['output'][0]['source.domain_suffix'] == 'com' |
142 | | - |
143 | | - |
144 | 81 | if __name__ == '__main__': # pragma: no cover |
145 | 82 | unittest.main() |
0 commit comments