1
|
|
|
""" |
2
|
|
|
:Copyright: 2007-2021 Jochen Kupperschmidt |
3
|
|
|
:License: MIT, see LICENSE for details. |
4
|
|
|
""" |
5
|
|
|
|
6
|
|
|
import pytest |
7
|
|
|
|
8
|
|
|
from weitersager.config import Config, HttpConfig, IrcConfig |
9
|
|
|
from weitersager.processor import Processor |
10
|
|
|
from weitersager.signals import irc_channel_joined, message_received |
11
|
|
|
|
12
|
|
|
|
13
|
|
|
@pytest.fixture |
14
|
|
|
def processor(): |
15
|
|
|
http_config = HttpConfig('localhost', 8080, set()) |
16
|
|
|
irc_config = IrcConfig(None, 'Nick', 'Nick', set()) |
17
|
|
|
config = Config(log_level="debug", http=http_config, irc=irc_config) |
18
|
|
|
return Processor(config) |
19
|
|
|
|
20
|
|
|
|
21
|
|
|
def test_message_handled(processor): |
22
|
|
|
channel_name = '#foo' |
23
|
|
|
text = 'Knock, knock.' |
24
|
|
|
|
25
|
|
|
received_signal_data = [] |
26
|
|
|
|
27
|
|
|
def say(channel_name, text): |
28
|
|
|
received_signal_data.append((channel_name, text)) |
29
|
|
|
|
30
|
|
|
processor.irc_bot.say = say |
31
|
|
|
|
32
|
|
|
fake_channel_join(channel_name) |
33
|
|
|
|
34
|
|
|
send_message_received_signal(channel_name, text) |
35
|
|
|
|
36
|
|
|
processor.process_queue(timeout_seconds=1) |
37
|
|
|
|
38
|
|
|
assert received_signal_data == [ |
39
|
|
|
(channel_name, text), |
40
|
|
|
] |
41
|
|
|
|
42
|
|
|
|
43
|
|
|
def fake_channel_join(channel_name): |
44
|
|
|
irc_channel_joined.send(channel_name=channel_name) |
45
|
|
|
|
46
|
|
|
|
47
|
|
|
def send_message_received_signal(channel_name, text): |
48
|
|
|
source_address = ('127.0.0.1', 12345) |
49
|
|
|
message_received.send( |
50
|
|
|
None, |
51
|
|
|
channel_name=channel_name, |
52
|
|
|
text=text, |
53
|
|
|
source_address=source_address, |
54
|
|
|
) |
55
|
|
|
|