This repository was archived by the owner on Apr 27, 2019. It is now read-only.
File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -7,9 +7,6 @@ class Announcer(BasePlugin):
77 """
88 name = 'announcer_plugin'
99
10- def activate (self ):
11- super (Announcer , self ).activate ()
12-
1310 def after_connect_success (self , data ):
1411 self .factory .broadcast (
1512 '{} logged in.' .format (
Original file line number Diff line number Diff line change @@ -10,9 +10,8 @@ class ChatLogger(BasePlugin):
1010
1111 def on_chat_sent (self , data ):
1212 parsed = chat_sent ().parse (data .data )
13- parsed .message = parsed .message .decode ('utf-8' )
1413 self .logger .info (
1514 'Chat message sent: <%s> %s' ,
1615 self .protocol .player .name ,
17- parsed .message
16+ parsed .message . decode ( 'utf-8' )
1817 )
Original file line number Diff line number Diff line change 1+ from unittest import TestCase
2+
3+ from mock import Mock , patch
4+
5+ from plugins .chat_logger .chat_logger import ChatLogger
6+
7+
8+ class ChatLoggerTestCase (TestCase ):
9+
10+ @patch ('plugins.chat_logger.chat_logger.chat_sent' )
11+ def test_on_chat_sent (self , mock_chat_sent ):
12+ mock_data = Mock (data = 'data data' )
13+ mock_parsed = Mock ()
14+ mock_parsed .parse .return_value = Mock (message = 'test message' )
15+ mock_chat_sent .return_value = mock_parsed
16+ mock_logger = Mock ()
17+ mock_protocol = Mock ()
18+ mock_protocol .player .name = 'player name'
19+ plugin = ChatLogger ()
20+ plugin .protocol = mock_protocol
21+ plugin .logger = mock_logger
22+
23+ plugin .on_chat_sent (mock_data )
24+ mock_parsed .parse .assert_called_with ('data data' )
25+ mock_logger .info .assert_called_with (
26+ 'Chat message sent: <%s> %s' , 'player name' , 'test message'
27+ )
You can’t perform that action at this time.
0 commit comments