Skip to content

Commit a0d7aa7

Browse files
tst: test_bot_library: simpler tests for failing init
1 parent 2dcf46d commit a0d7aa7

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

intelmq/tests/lib/test_bot_library_mode.py

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@
1212
import json
1313
import unittest
1414
from os.path import dirname, join
15+
from pytest import raises
1516

1617
import intelmq.tests.bots.experts.domain_suffix.test_expert as domain_suffix_expert_test
1718
from intelmq.bots.experts.domain_suffix.expert import DomainSuffixExpertBot
18-
from intelmq.bots.experts.jinja.expert import JinjaExpertBot
1919
from intelmq.bots.experts.taxonomy.expert import TaxonomyExpertBot
2020
from intelmq.bots.experts.url.expert import URLExpertBot
21-
from intelmq.lib.bot import BotLibSettings, Dict39
21+
from intelmq.lib.bot import BotLibSettings, Dict39, ExpertBot
2222
from intelmq.lib.message import Message, MessageFactory
2323
from intelmq.tests.lib import test_parser_bot
2424

@@ -28,11 +28,11 @@
2828
'source.urlpath': '/',
2929
'protocol.application': 'http',
3030
'protocol.transport': 'tcp'}
31-
BOT_CONFIG_JINJA_FAILING = Dict39({
32-
'fields': {
33-
'feed.url': "{{ error! msg['source.fqdn'] | upper }}"
34-
}
35-
})
31+
32+
33+
class BrokenInitExpertBot(ExpertBot):
34+
def init(self):
35+
raise ValueError('This initialization intionally raises an error!')
3636

3737

3838
def assertMessageEqual(actual, expected):
@@ -94,14 +94,12 @@ def test_url_and_taxonomy():
9494
assert queues['output'] == [Dict39(EXAMPLE_DATA_URL_OUT) | {'classification.taxonomy': 'other', 'classification.type': 'undetermined'}]
9595

9696

97-
def test_bot_exception_import():
97+
def test_bot_exception_init():
9898
"""
9999
When a bot raises an exception during Bot initialization
100100
"""
101-
try:
102-
JinjaExpertBot('jinja', settings=BotLibSettings | BOT_CONFIG_JINJA_FAILING)
103-
except:
104-
pass
101+
with raises(ValueError):
102+
BrokenInitExpertBot('broken', settings=BotLibSettings)
105103

106104

107105
def test_bot_multi_message():

0 commit comments

Comments
 (0)