Skip to content

Commit 5e313a6

Browse files
committed
Test importing bots. Fix debian/control and guide
1 parent 959ef04 commit 5e313a6

File tree

5 files changed

+38
-2
lines changed

5 files changed

+38
-2
lines changed

contrib/example-extension-package/mybots/bots/collectors/custom/collector.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,9 @@
33
SPDX-License-Identifier: AGPL-3.0-or-later
44
"""
55

6+
# Use your package as usual
7+
from mybots.lib import common
8+
69
from intelmq.lib.bot import CollectorBot
710

811

@@ -14,7 +17,7 @@ class ExampleAdditionalCollectorBot(CollectorBot):
1417
def process(self):
1518
report = self.new_report()
1619
if self.raw: # noqa: Set as parameter
17-
report['raw'] = 'test'
20+
report['raw'] = common.return_value('example')
1821
self.send_message(report)
1922

2023

debian/control

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ Depends: bash-completion,
4141
python3-ruamel.yaml,
4242
python3-termstyle (>= 0.1.10),
4343
python3-tz,
44+
python3-importlib-metadata,
4445
redis-server,
4546
systemd,
4647
${misc:Depends},

docs/dev/guide.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ bots work with IntelMQ, you need to ensure that
916916

917917
Apart from these requirements, your package can use any of the usual package features. We strongly
918918
recommend following the same principles and main guidelines as the official bots. This will ensure
919-
experience when using official and additional bots.
919+
the same experience when using official and additional bots.
920920

921921
Naming convention
922922
=================

docs/user/installation.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ Native deb/rpm packages
4545

4646
These are the operating systems which are currently supported by packages:
4747

48+
* **Debian 10** Buster
49+
50+
* Enable the backport repository by the line ``deb-src http://deb.debian.org/debian buster-backports main contrib non-free`` to the file ``/etc/apt/sources.list`` first.
51+
4852
* **Debian 11** Bullseye
4953
* **openSUSE Tumbleweed**
5054
* **Ubuntu 20.04** Focal Fossa

intelmq/tests/lib/test_utils.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@
3131
from intelmq.lib.test import skip_internet
3232
from intelmq.tests.test_conf import CerberusTests
3333

34+
try:
35+
from importlib.metadata import EntryPoint
36+
except ImportError:
37+
from importlib_metadata import EntryPoint
38+
39+
3440
LINES = {'spare': ['Lorem', 'ipsum', 'dolor'],
3541
'short': ['{}: Lorem', '{}: ipsum',
3642
'{}: dolor'],
@@ -318,6 +324,28 @@ def _mock_importing(module):
318324
bot_count = sum([len(val) for val in bots.values()])
319325
self.assertEqual(1, bot_count)
320326

327+
def test_list_all_bots_filters_entrypoints(self):
328+
entries = [
329+
EntryPoint("intelmq.bots.collector.api.collector_api",
330+
"intelmq.bots.collector.api.collector_api:BOT.run", group="console_scripts"),
331+
EntryPoint("intelmq.bots.collector.awesome.my_bot",
332+
"awesome.extension.package.collector:BOT.run", group="console_scripts"),
333+
EntryPoint("not.a.bot", "not.a.bot:run", group="console_scripts")
334+
]
335+
336+
with unittest.mock.patch.object(utils, "_get_console_entry_points", return_value=entries):
337+
with unittest.mock.patch.object(utils.importlib, "import_module") as import_mock:
338+
import_mock.side_effect = SyntaxError() # stop processing after import try
339+
utils.list_all_bots()
340+
341+
import_mock.assert_has_calls(
342+
[
343+
unittest.mock.call("intelmq.bots.collector.api.collector_api"),
344+
unittest.mock.call("awesome.extension.package.collector"),
345+
]
346+
)
347+
self.assertEqual(2, import_mock.call_count)
348+
321349
def test_get_bots_settings(self):
322350
with unittest.mock.patch.object(utils, "get_runtime", new_get_runtime):
323351
runtime = utils.get_bots_settings()

0 commit comments

Comments
 (0)