| Total Complexity | 3 |
| Total Lines | 50 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | """ |
||
| 2 | :Copyright: 2007-2020 Jochen Kupperschmidt |
||
| 3 | :License: MIT, see LICENSE for details. |
||
| 4 | """ |
||
| 5 | |||
| 6 | from weitersager.processor import Processor |
||
| 7 | from weitersager.signals import ( |
||
| 8 | channel_joined, |
||
| 9 | message_approved, |
||
| 10 | message_received, |
||
| 11 | ) |
||
| 12 | |||
| 13 | |||
| 14 | def test_message_handled(): |
||
| 15 | channel_name = '#foo' |
||
| 16 | text = 'Knock, knock.' |
||
| 17 | |||
| 18 | received_signal_data = [] |
||
| 19 | |||
| 20 | @message_approved.connect |
||
| 21 | def handle_message_approved(sender, **data): |
||
| 22 | received_signal_data.append(data) |
||
| 23 | |||
| 24 | processor = Processor() |
||
| 25 | processor.connect_to_signals() |
||
| 26 | |||
| 27 | fake_channel_join(channel_name) |
||
| 28 | |||
| 29 | send_message_received_signal(channel_name, text) |
||
| 30 | |||
| 31 | assert received_signal_data == [ |
||
| 32 | { |
||
| 33 | 'channel_name': '#foo', |
||
| 34 | 'text': text, |
||
| 35 | }, |
||
| 36 | ] |
||
| 37 | |||
| 38 | |||
| 39 | def fake_channel_join(channel_name): |
||
| 40 | channel_joined.send(channel_name=channel_name) |
||
| 41 | |||
| 42 | |||
| 43 | def send_message_received_signal(channel_name, text): |
||
| 44 | source_address = ('127.0.0.1', 12345) |
||
| 45 | message_received.send( |
||
| 46 | None, |
||
| 47 | channel_name=channel_name, |
||
| 48 | text=text, |
||
| 49 | source_address=source_address, |
||
| 50 | ) |
||
| 51 |