Skip to content
This repository was archived by the owner on Apr 27, 2019. It is now read-only.

Commit 0ceb498

Browse files
committed
[142] Added unit test for Announcer
1 parent f9b270e commit 0ceb498

2 files changed

Lines changed: 51 additions & 2 deletions

File tree

plugins/announcer_plugin/announcer_plugin.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22

33

44
class Announcer(BasePlugin):
5-
'''
5+
"""
66
Broadcasts a message whenever a player joins or leaves the server.
7-
'''
7+
"""
88
name = 'announcer_plugin'
99

1010
def activate(self):
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
from unittest import TestCase
2+
3+
from mock import Mock
4+
5+
from plugins.announcer_plugin.announcer_plugin import Announcer
6+
7+
8+
class AnnoucerTestCase(TestCase):
9+
def test_after_connect_success(self):
10+
mock_factory = Mock()
11+
mock_config = Mock(colors='colors config')
12+
mock_protocol = Mock()
13+
mock_protocol.player.colored_name.return_value = 'player name'
14+
plugin = Announcer()
15+
plugin.factory = mock_factory
16+
plugin.config = mock_config
17+
plugin.protocol = mock_protocol
18+
19+
plugin.after_connect_success(None)
20+
mock_factory.broadcast.assert_called_with(
21+
'player name logged in.', 'Announcer'
22+
)
23+
mock_protocol.player.colored_name.assert_called_with('colors config')
24+
25+
def test_on_client_disconnect_request(self):
26+
mock_factory = Mock()
27+
mock_config = Mock(colors='colors config')
28+
mock_protocol = Mock()
29+
mock_protocol.player.colored_name.return_value = 'player name'
30+
plugin = Announcer()
31+
plugin.factory = mock_factory
32+
plugin.config = mock_config
33+
plugin.protocol = mock_protocol
34+
35+
plugin.on_client_disconnect_request(None)
36+
mock_factory.broadcast.assert_called_with(
37+
'player name logged out.', 'Announcer'
38+
)
39+
mock_protocol.player.colored_name.assert_called_with('colors config')
40+
41+
def test_on_client_disconnect_request_player_is_none(self):
42+
mock_factory = Mock()
43+
mock_protocol = Mock()
44+
mock_protocol.player = None
45+
plugin = Announcer()
46+
plugin.factory = mock_factory
47+
plugin.protocol = mock_protocol
48+
49+
self.assertFalse(mock_factory.broadcast.called)

0 commit comments

Comments
 (0)